关于python:nameko-是一个服务一个-amqp-连接还是每个队列-work-函数一个-amqp-连接

38次阅读

共计 1561 个字符,预计需要花费 4 分钟才能阅读完成。

class AddService:
    name = 'add_service'

    @event_handler('productor_service', 'a')
    @event_handler('productor_service', 'b')
    def handle_message(self, payload: str):
        logger.debug(f'handle_message {payload}')

    @rpc
    @context_id_dec
    def add(self, a: int, b: int, /, context_id: str) -> int | None:
        try:

            logger.debug(f'收到一个加法计算申请:{a},{b},{asgi_context_id.get()}')
            # time.sleep(1000)
            return a+b
        except Exception as error:
            logger.exception(error)
            return None

    @http('GET', '/hi')
    def hi(self, request):
        return "hello world"

    @http('GET', '/ha')
    def ha(self, request):
        time.sleep(10)
        return 'ok'

nameko run services:AddService --config ./config.yaml 应用该命令,发现只有一个连贯:

class TrashCanService:
    name = 'trash_scan_service'

    @event_handler('hi_api', 'rubbish')
    def receive(self, message: str):
        logger.debug(f'开始生产音讯, {message}')
        response = requests.get('http://127.0.0.1:50010')
        logger.debug(f'{message}, {response.text}')

    receive.create_queue_only = True

    @event_handler('drop_throw_rubbish_service', 'drop_rubbish')
    def receive_by_rpc(self, message: str):
        pass


class AddService:
    name = 'add_service'

    @event_handler('productor_service', 'a')
    @event_handler('productor_service', 'b')
    def handle_message(self, payload: str):
        logger.debug(f'handle_message {payload}')

    @rpc
    @context_id_dec
    def add(self, a: int, b: int, /, context_id: str) -> int | None:
        try:

            logger.debug(f'收到一个加法计算申请:{a},{b},{asgi_context_id.get()}')
            # time.sleep(1000)
            return a+b
        except Exception as error:
            logger.exception(error)
            return None

    @http('GET', '/hi')
    def hi(self, request):
        return "hello world"

    @http('GET', '/ha')
    def ha(self, request):
        time.sleep(10)
        return 'ok'

然而这样,两个服务,一共两个 amqp 连贯:

所以 nameko 是一个服务一个 amqp 连贯,还是每个队列 work 函数一个 amqp 连贯? 这个问题的论断就是:nameko 是一个服务一个 amqp 连贯

正文完
 0