Putting it all together

Let's try out the code we have just created. Start by saving a new key-value pair to Redis using the redis-cli:

127.0.0.1:6379> set msg1 "this is a test"
OK

Now start our Nameko services:

$ nameko run temp_messenger.service --config config.yaml

We can now use nameko shell to make remote calls to our new MessageService:

>>> n.rpc.message_service.get_message('msg1') 
'this is a test' 

As expected, we were able to retrieve a message that we set earlier using redis-cli via our MessageService entrypoint.

Let's now try to get a message that does not exist:

    >>> n.rpc.message_service.get_message('i_dont_exist')
    Traceback (most recent call last):
      File "<console>", line 1, in <module>
     File "/Users/marcuspen/.virtualenvs/temp_messenger/lib/python3.6/site-packages/nameko/rpc.py", ...

Get Python Programming Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.