You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
JimZhang 2ac4e75bc9 feat: get cient name by connnection info 1 year ago
busrtworker feat: get cient name by connnection info 1 year ago
example init project 1 year ago
tests init project 1 year ago
.gitignore init project 1 year ago
LICENSE init project 1 year ago
README.md init project 1 year ago
poetry.lock feat: change compress lib 1 year ago
pyproject.toml feat: get cient name by connnection info 1 year ago

README.md

Busrt Worker

BUS/RT是一个快速、灵活且非常易于使用的框架它使用Rust/Tokio编写受到NATS、ZeroMQ和Nanomsg的启发。

Busrt Worker是一个基于busrt消息中间件的异步框架它对Python库进行了封装使其更易于使用。

特点

  • 异步Busrt Worker基于python asyncio异步引擎可以轻松处理高并发请求。
  • 易用性Busrt Worker对原生的busrt python客户端进行了封装使用装饰器即可轻松创建rpc服务。
  • 高性能BUS/RT 使用Rust/Tokio编写具有出色的性能和可靠性。

用法

要使用Busrt Worker请按照以下步骤操作

  1. 安装Busrt Workerpip install busrt-worker
  2. 导入Busrt Worker在您的Python项目中导入Busrt Worker。
  3. 创建Busrt Worker App创建一个App对象并注册连接信息。
  4. 处理消息:使用装饰器指明消息处理方式。

以下是一个示例代码片段演示如何使用Busrt Worker

import asyncio

from loguru import logger

from busrtworker import App, ConnectionInfo
# 创建 App对象
app = App()

# 连接信息
api_ci = ConnectionInfo('api', 'localhost:9800', 'busrt.worker.test', static=True, topic='test/#')
caller_ci = ConnectionInfo('caller', 'localhost:9800', 'busrt.worker.test', static=True)

# 注册连接
api = app.registry(api_ci)
app.registry(caller_ci)

# rpc调用
@api.on_call()
def add(a, b):
    return a + b

# 主题订阅
@api.subscribe('test/:name')
def print_name(name: str):
    logger.info(f'{name} pub message')

# 钩子函数注册
@app.run_on_startup
async def test(server):
    async def call():
        await asyncio.sleep(1)
        logger.info(f'call remote add result {(await app.caller.add(api_ci.final_name,a=1, b=2))}')
        await app.caller.send('test/i_am_caller')
    asyncio.create_task(call())

# 启动程序
app.run()

License

The MIT License.