Skip to main content

Python AMQP RPC 库

项目描述

格雷伯爵茶

Earlgrey 是一个 python 库,它提供了一种使用 RabbitMQ 在进程之间发布和使用消息的便捷方式。它被抽象为 RPC 模式。

如何使用

# RPC methods
class Task:
    @message_queue_task
    async def echo(self, value):
        return value

# Client stub
class Stub(MessageQueueStub[Task]):
    TaskType = Task

# Server service
class Service(MessageQueueService[Task]):
    TaskType = Task

async def run():
    route_key = 'any same string between processes'

    client = Stub('localhost', route_key)
    server = Service('localhost', route_key)

    await client.connect()
    await server.connect()

    result = await client.async_task().echo('any value')
    print(result)  # 'any value'

loop = asyncio.get_event_loop()
loop.run_until_complete(run())

警告

实际上MessageQueueStub不需要完全Task实现方法的确切类。它只需要方法的签名。

# client side.
class Task:
    @message_queue_task
    async def echo(self, value):
        # Just signature. It is okay. Do not need implemetation.
        # But server must have its implementation
        pass

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

earlgrey-0.2.2.tar.gz (10.1 kB 查看哈希

已上传 source

内置分布

earlgrey-0.2.2-py3-none-any.whl (25.7 kB 查看哈希

已上传 py3