# 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 Worker:`pip install busrt-worker`
2. 导入Busrt Worker:在您的Python项目中导入Busrt Worker。
3. 创建Busrt Worker App:创建一个App对象,并注册连接信息。
4. 处理消息:使用装饰器指明消息处理方式。
以下是一个示例代码片段,演示如何使用Busrt Worker:
```python
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.
Raw data
{
"_id": null,
"home_page": "https://git.loom.run/Coder/amqp-worker",
"name": "busrt-worker",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10,<4.0",
"maintainer_email": "",
"keywords": "busrt,message,rpc",
"author": "JimZhang",
"author_email": "zzl22100048@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/91/92/dcf8dc63b055b6544a8abc03b43eacea636691cf1db71c2ef8677ce7ac96/busrt_worker-0.1.7.tar.gz",
"platform": null,
"description": "# Busrt Worker\n> `BUS/RT`\u662f\u4e00\u4e2a\u5feb\u901f\u3001\u7075\u6d3b\u4e14\u975e\u5e38\u6613\u4e8e\u4f7f\u7528\u7684\u6846\u67b6\uff0c\u5b83\u4f7f\u7528Rust/Tokio\u7f16\u5199\uff0c\u53d7\u5230NATS\u3001ZeroMQ\u548cNanomsg\u7684\u542f\u53d1\u3002\n\nBusrt Worker\u662f\u4e00\u4e2a\u57fa\u4e8ebusrt\u6d88\u606f\u4e2d\u95f4\u4ef6\u7684\u5f02\u6b65\u6846\u67b6\uff0c\u5b83\u5bf9Python\u5e93\u8fdb\u884c\u4e86\u5c01\u88c5\uff0c\u4f7f\u5176\u66f4\u6613\u4e8e\u4f7f\u7528\u3002\n\n\n## \u7279\u70b9\n\n- \u5f02\u6b65\uff1aBusrt Worker\u57fa\u4e8epython asyncio\u5f02\u6b65\u5f15\u64ce\uff0c\u53ef\u4ee5\u8f7b\u677e\u5904\u7406\u9ad8\u5e76\u53d1\u8bf7\u6c42\u3002\n- \u6613\u7528\u6027\uff1aBusrt Worker\u5bf9\u539f\u751f\u7684busrt python\u5ba2\u6237\u7aef\u8fdb\u884c\u4e86\u5c01\u88c5\uff0c\u4f7f\u7528\u88c5\u9970\u5668\u5373\u53ef\u8f7b\u677e\u521b\u5efarpc\u670d\u52a1\u3002\n- \u9ad8\u6027\u80fd\uff1aBUS/RT \u4f7f\u7528Rust/Tokio\u7f16\u5199\uff0c\u5177\u6709\u51fa\u8272\u7684\u6027\u80fd\u548c\u53ef\u9760\u6027\u3002\n\n## \u7528\u6cd5\n\n\u8981\u4f7f\u7528Busrt Worker\uff0c\u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a\n\n1. \u5b89\u88c5Busrt Worker\uff1a`pip install busrt-worker`\n2. \u5bfc\u5165Busrt Worker\uff1a\u5728\u60a8\u7684Python\u9879\u76ee\u4e2d\u5bfc\u5165Busrt Worker\u3002\n3. \u521b\u5efaBusrt Worker App\uff1a\u521b\u5efa\u4e00\u4e2aApp\u5bf9\u8c61\uff0c\u5e76\u6ce8\u518c\u8fde\u63a5\u4fe1\u606f\u3002\n4. \u5904\u7406\u6d88\u606f\uff1a\u4f7f\u7528\u88c5\u9970\u5668\u6307\u660e\u6d88\u606f\u5904\u7406\u65b9\u5f0f\u3002\n\n\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\u7247\u6bb5\uff0c\u6f14\u793a\u5982\u4f55\u4f7f\u7528Busrt Worker\uff1a\n\n```python\nimport asyncio\n\nfrom loguru import logger\n\nfrom busrtworker import App, ConnectionInfo\n# \u521b\u5efa App\u5bf9\u8c61\napp = App()\n\n# \u8fde\u63a5\u4fe1\u606f\napi_ci = ConnectionInfo('api', 'localhost:9800', 'busrt.worker.test', static=True, topic='test/#')\ncaller_ci = ConnectionInfo('caller', 'localhost:9800', 'busrt.worker.test', static=True)\n\n# \u6ce8\u518c\u8fde\u63a5\napi = app.registry(api_ci)\napp.registry(caller_ci)\n\n# rpc\u8c03\u7528\n@api.on_call()\ndef add(a, b):\n return a + b\n\n# \u4e3b\u9898\u8ba2\u9605\n@api.subscribe('test/:name')\ndef print_name(name: str):\n logger.info(f'{name} pub message')\n\n# \u94a9\u5b50\u51fd\u6570\u6ce8\u518c\n@app.run_on_startup\nasync def test(server):\n async def call():\n await asyncio.sleep(1)\n logger.info(f'call remote add result {(await app.caller.add(api_ci.final_name,a=1, b=2))}')\n await app.caller.send('test/i_am_caller')\n asyncio.create_task(call())\n\n# \u542f\u52a8\u7a0b\u5e8f\napp.run()\n```\n\n## License\nThe MIT License.",
"bugtrack_url": null,
"license": "MIT",
"summary": "busrt-worker is a Python-based async busrt message handle framework",
"version": "0.1.7",
"project_urls": {
"Homepage": "https://git.loom.run/Coder/amqp-worker",
"Repository": "https://git.loom.run/Coder/amqp-worker"
},
"split_keywords": [
"busrt",
"message",
"rpc"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "efeaca84bc1fe765e53309a5fb7ced66a548fdd82e2e9cddd64c2d48cb260197",
"md5": "ea57898aab22fe3ed8d2363ebf64f48f",
"sha256": "f8a26f3a270d6ca3a07ef19e31c80638871a1237d6f3720640c237258442800c"
},
"downloads": -1,
"filename": "busrt_worker-0.1.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ea57898aab22fe3ed8d2363ebf64f48f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10,<4.0",
"size": 20774,
"upload_time": "2023-11-06T00:51:51",
"upload_time_iso_8601": "2023-11-06T00:51:51.719461Z",
"url": "https://files.pythonhosted.org/packages/ef/ea/ca84bc1fe765e53309a5fb7ced66a548fdd82e2e9cddd64c2d48cb260197/busrt_worker-0.1.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9192dcf8dc63b055b6544a8abc03b43eacea636691cf1db71c2ef8677ce7ac96",
"md5": "7856b309dffa9cb934d11f562d794cf5",
"sha256": "5ff70d895afddfdc590593b312f1e023941b69f285a79e1b492f4090d6303cc9"
},
"downloads": -1,
"filename": "busrt_worker-0.1.7.tar.gz",
"has_sig": false,
"md5_digest": "7856b309dffa9cb934d11f562d794cf5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10,<4.0",
"size": 16425,
"upload_time": "2023-11-06T00:51:53",
"upload_time_iso_8601": "2023-11-06T00:51:53.231961Z",
"url": "https://files.pythonhosted.org/packages/91/92/dcf8dc63b055b6544a8abc03b43eacea636691cf1db71c2ef8677ce7ac96/busrt_worker-0.1.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-06 00:51:53",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "busrt-worker"
}