nameko 获取自身服务列表

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()

    @rpc
    def introspect(self):
        entrypoints = defaultdict(list)
        for ep in self.entrypoint_list:
            entrypoints[ep.method_name].append(type(ep).__name__)
        return entrypoints

你可能感兴趣的:(nameko 获取自身服务列表)