How it works

Let's first look at the implementation of the microservice in hello_microservice.py.  There really isn't a lot of code, so here it all is:

from nameko.rpc import rpcclass HelloMicroService:    name = "hello_microservice"    @rpc    def hello(self, name):        print('Received a request from: ' + name)        return "Hello, {}!".format(name)

There are two thing to point out about this class. The first is the declaration of name = "hello_microservice".  This is a declaration of the actual name of the microservice. This member variable is used instead of the class name.

The second is the use of the @rpc attribute on the hello method. This is a Nameko attribute that specifies that this method should be exposed as an rpc style method by the microservice. ...

Get Python Web Scraping Cookbook 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.