跳转到主要内容

PATIO RabbitMQ代理实现

项目描述

PyPI - License Wheel Mypy PyPI PyPI Coverage Status tox

PATIO Rabbitmq

PATIO是Python异步异步IO的缩写。

此软件包提供RabbitMQ代理实现。

示例

任务执行器

import asyncio
import operator
from functools import reduce

from patio import Registry, ThreadPoolExecutor

from patio_rabbitmq import RabbitMQBroker


rpc = Registry(project="patio-rabbitmq", auto_naming=False)


@rpc("mul")
def mul(*args):
    return reduce(operator.mul, args)


async def main():
    async with ThreadPoolExecutor(rpc, max_workers=16) as executor:
        async with RabbitMQBroker(
            executor, amqp_url="amqp://guest:guest@localhost/",
        ) as broker:
            await broker.join()


if __name__ == "__main__":
    asyncio.run(main())

任务生产者

import asyncio

from patio import NullExecutor, Registry

from patio_rabbitmq import RabbitMQBroker


async def main():
    async with NullExecutor(Registry(project="patio-rabbitmq")) as executor:
        async with RabbitMQBroker(
            executor, amqp_url="amqp://guest:guest@localhost/",
        ) as broker:
            print(
                await asyncio.gather(
                    *[
                        broker.call("mul", i, i, timeout=1) for i in range(10)
                    ]
                ),
            )


if __name__ == "__main__":
    asyncio.run(main())

项目详情


下载文件

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

源分布

patio_rabbitmq-0.1.1.tar.gz (2.8 kB 查看哈希值)

上传时间:

构建分布

patio_rabbitmq-0.1.1-py3-none-any.whl (3.6 kB 查看哈希值)

上传时间: Python 3

由以下支持