Automatic Service Discovery

From @authentik8 on Mon Mar 05 2018 17:01:00 GMT+0000 (UTC)

Is there a method/property in the Nameko MethodProxy / ServiceProxy API that allows for the retrieval of the available RPC methods on a given service?

Copied from original issue:

From @mattbennett on Tue Mar 06 2018 07:01:11 GMT+0000 (UTC)

Not out of the box, but it’s trivial to write a service that can introspect itself:

from collections import defaultdict

from nameko.extensions import DependencyProvider
from nameko.rpc import rpc

class EntrypointList(DependencyProvider):

    def get_dependency(self, worker_ctx):
        # all Extensions have access to self.container
        return list(self.container.entrypoints)

class Service:
    name = "discovery"

    entrypoint_list = EntrypointList()

    def introspect(self):
        entrypoints = defaultdict(list)
        for ep in self.entrypoint_list:
        return entrypoints
$ nameko shell
Nameko Python 3.5.3 (default, Jun 30 2017, 18:28:54)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] shell on darwin
Broker: pyamqp://guest:guest@localhost
>>> n.rpc.discovery.introspect()
{'introspect': ['Rpc']}