How to invoke the microservice from a Python script

137 views Asked by At

This code defines the services:

from nameko.rpc import rpc


class GreetingService:
    name = "greeting_service"

    @rpc
    def hello(self, name):
        return "Hello, {}!".format(name)
    
class MultiplyService:
    name = "multiply_service"
    
    @rpc
    def multiple(self,a,b):
        return str(int(a) * int(b))

I have the services running: enter image description here

I can open a nameko shell and access the microservice: enter image description here enter image description here

I want to access the microservice from another Python script. What am I missing? enter image description here

1

There are 1 answers

0
Matt On

The n global is only available inside nameko shell.

To invoke an RPC from a script, you need to use the one of the "standalone" clients in nameko.standalone.rpc.

Example in the docs here https://nameko.readthedocs.io/en/stable/built_in_extensions.html#rpc