Creating your first Nameko microservice

Let's start by creating a new folder titled temp_messenger and placing a new file inside, named service.py, with the following code:

from nameko.rpc import rpc 
 
class KonnichiwaService: 
 
    name = 'konnichiwa_service' 
 
    @rpc 
    def konnichiwa(self): 
        return 'Konnichiwa!' 

We first start by importing rpc from nameko.rpc. This will allow us to decorate our methods with the rpc decorator and expose them as entrypoints into our service. An entrypoint is any method in a Nameko service that acts as a gateway into our service.

In order to create a Nameko service, we simply create a new class, KonnichiwaService, and assign it a name attribute. The name attribute gives it a namespace; this will be used later when we attempt ...

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.