ExamplesΒΆ
In the examples
directory you can find some examples of microservices
example_client
- an example usage of thegemstone.RemoteService
class for communication with microservices.There you will find two files:
service.py
andclient.py
In
service.py
you have a basic microservice that exposes two methods:say_hello(name)
andslow_method(seconds)
. You can start it with the commandpython service.py
In
client.py
you can find some basic interaction with the service started above.example_events
- an example for the publisher-subscribe pattern in the microservice communication. There are two files:service.py
andservice2.py
. You can start them with the commandsWarning
You are going to need a RabbitMQ server running somewhere because the example uses it as message exchange transport
python service.py python service2.py
Note
Those two commands must be executed in separate terminals/cmds because they are blocking.
What happens here is:
- the
service.py
subscribes to"said_hello"
events. - the
service2.py
exposes a public methodsay_hello(name)
. When called, emits an"said_hello"
event and then processes the request.
After that, you can send a JSONRPC request to
http://127.0.0.1:8000/api
with the body{ "jsonrpc": "2.0", "method": "say_hello", "params": {"name": "world"}, "id": 1 }
and watch what happens.
- the