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 to make a remote call to the service.
We've written a method on our service which simply returns the word Konnichiwa!
. Notice how this method is decorated with rpc
. The konnichiwa
method is now going to be exposed via RPC...