# RabiBridge
[![fury](https://badge.fury.io/py/RabiBridge.svg)](https://badge.fury.io/py/RabiBridge)
[![licence](https://img.shields.io/github/license/GoodManWEN/RabiBridge)](https://github.com/GoodManWEN/RabiBridge/blob/master/LICENSE)
[![pyversions](https://img.shields.io/pypi/pyversions/RabiBridge.svg)](https://pypi.org/project/RabiBridge/)
[![Publish](https://github.com/GoodManWEN/RabiBridge/workflows/Publish/badge.svg)](https://github.com/GoodManWEN/RabiBridge/actions?query=workflow:Publish)
[![Docs](https://github.com/GoodManWEN/RabiBridge/workflows/Docs/badge.svg)](https://github.com/GoodManWEN/RabiBridge/actions?query=workflow:Docs)
This is a lightweight RPC framework based on RabbitMQ, designed to achieve network service decoupling and traffic peak shaving and protect your backend service. Applicable to FastAPI / aiohttp and other asynchronous frameworks
## Catalogue
- [Feature](#Feature)
- [Dependency](#Dependency)
- [Quick Start](#Quick-Start)
- [Documentation](#Documentation)
- [Configuration](#Configuration)
- [Performance](#Performance)
- [Licence](#Licence)
## Feature
- Based on message queues
- Low Latency
- Distributed services and horizontal scaling
- Fully asynchronous framework
- Connections ensured by tls
- Stable under extensive stress testing
## Dependency
- Python 3.x
- RabbitMQ
## Installation
```
pip install RabiBridge
```
## Quick Start
1. First start your rabbitmq service
```sh
docker run -d \
--name rabbitmq \
-e RABBITMQ_DEFAULT_USER=admin \
-e RABBITMQ_DEFAULT_PASS=123456 \
-p 5672:5672 \
-p 15672:15672 \
rabbitmq:management
```
2. Import `RabiBridge`, create a function to call, register and run serve.
```python
# -*- coding: utf-8 -*-
# File name: service.py
import asyncio
from rabibridge import RMQServer, register_call
@register_call(timeout=10)
async def fibonacci(n: int):
if n <= 0:
return 0
elif n == 1:
return 1
return await fibonacci(n-1) + await fibonacci(n-2)
async def main():
bridge = RMQServer(host="localhost", port=5672, username="admin", password="123456")
bridge.load_services(globals()) # Automatic capture procedure of the main namespace
async with bridge:
await bridge.run_serve()
asyncio.run(main())
```
3. Call remotely.
```python
# -*- coding: utf-8 -*-
# File name: client.py
import asyncio
from rabibridge import RMQClient
async def main():
async with RMQClient(host="localhost", port=5672, username="admin", password="123456") as bridge:
err_code, result = await bridge.remote_call('fibonacci', (10, ))
print(f"Result is {result}")
# >>> Result is 55
asyncio.run(main())
```
## Documentation
For the detailed function description, please refer to the [API reference](https://goodmanwen.github.io/RabiBridge/).
[Production deployment example](https://github.com/GoodManWEN/RabiBridge/blob/main/docs/blogs/production_deployment_example.md)
[Encryption in configuration file](https://github.com/GoodManWEN/RabiBridge/blob/main/docs/blogs/encryption_in_configuration_file.md)
## Configuration
For production and other needs, to achieve higher convenience and stronger security, it is recommended to use configuration files instead of passing parameters. The configuration file options are as follows:
```toml
[rabbitmq]
RABBITMQ_HOST = 'localhost' # RabbitMQ configuration info, same below.
RABBITMQ_PORT = 5672
RABBITMQ_USERNAME = "admin"
RABBITMQ_PASSWORD = "fMgmG7+ooAYLjXdPnhInjQ==" # AES Encrypted, check "Encryption in configuration file"
[app]
DEBUG_MODE = false # Whether to run in Debug mode.
CID_MAX = 1073741824 # The maximum value of the independent ID assigned by
# the client for each message, which should not be
# too small or too large.
COMPRESS_THRESHOLD = 1024 # Stream compression algorithm will be enabled when
# the message size exceeds this byte threshold.
SERIALISER = 'msgpack' # Literal['msgpack', 'pickle', 'json']
[secret]
SECRET = "your secret that no one knows" # Avoid being known by anyone.
```
## Performance
![](https://github.com/GoodManWEN/RabiBridge/blob/main/misc/echo-performance-with-number-of-cpu-cores.png?raw=true)
Testing Platform:
```
CPU Model : Intel(R) Xeon(R) Platinum 8369B CPU @ 2.70GHz
CPU Cores : 16 Cores 2699.998 MHz x86_64
CPU Cache : L2 1280K & L3 49152K
OS : Ubuntu 22.04.4 LTS (64 Bit) KVM
Kernel : 5.15.0-106-generic
Total RAM : 950 MB / 30663 MB (4646 MB Buff)
Location : San Jose / US
Region : California
```
## Licence
The MIT License
Raw data
{
"_id": null,
"home_page": "https://github.com/GoodManWEN/RabiBridge",
"name": "RabiBridge",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "RabiBridge, rabbitmq, rpc, fastapi",
"author": "WEN",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/90/32/30767256c94d07c70df5938bb7d735902fd8099381cf245b2c89ee642d13/rabibridge-0.1.2.tar.gz",
"platform": null,
"description": "# RabiBridge\n\n[![fury](https://badge.fury.io/py/RabiBridge.svg)](https://badge.fury.io/py/RabiBridge)\n[![licence](https://img.shields.io/github/license/GoodManWEN/RabiBridge)](https://github.com/GoodManWEN/RabiBridge/blob/master/LICENSE)\n[![pyversions](https://img.shields.io/pypi/pyversions/RabiBridge.svg)](https://pypi.org/project/RabiBridge/)\n[![Publish](https://github.com/GoodManWEN/RabiBridge/workflows/Publish/badge.svg)](https://github.com/GoodManWEN/RabiBridge/actions?query=workflow:Publish)\n[![Docs](https://github.com/GoodManWEN/RabiBridge/workflows/Docs/badge.svg)](https://github.com/GoodManWEN/RabiBridge/actions?query=workflow:Docs)\n\nThis is a lightweight RPC framework based on RabbitMQ, designed to achieve network service decoupling and traffic peak shaving and protect your backend service. Applicable to FastAPI / aiohttp and other asynchronous frameworks\n\n## Catalogue\n- [Feature](#Feature)\n- [Dependency](#Dependency)\n- [Quick Start](#Quick-Start)\n- [Documentation](#Documentation)\n- [Configuration](#Configuration)\n- [Performance](#Performance)\n- [Licence](#Licence)\n\n## Feature\n- Based on message queues\n- Low Latency\n- Distributed services and horizontal scaling\n- Fully asynchronous framework\n- Connections ensured by tls\n- Stable under extensive stress testing\n\n## Dependency\n- Python 3.x\n- RabbitMQ\n\n## Installation\n\n```\npip install RabiBridge\n```\n\n## Quick Start\n\n1. First start your rabbitmq service\n```sh\ndocker run -d \\\n --name rabbitmq \\\n -e RABBITMQ_DEFAULT_USER=admin \\\n -e RABBITMQ_DEFAULT_PASS=123456 \\\n -p 5672:5672 \\\n -p 15672:15672 \\\n rabbitmq:management\n```\n\n2. Import `RabiBridge`, create a function to call, register and run serve.\n```python\n# -*- coding: utf-8 -*-\n# File name: service.py\nimport asyncio\nfrom rabibridge import RMQServer, register_call\n\n@register_call(timeout=10)\nasync def fibonacci(n: int):\n if n <= 0:\n return 0\n elif n == 1:\n return 1\n return await fibonacci(n-1) + await fibonacci(n-2)\n\nasync def main():\n bridge = RMQServer(host=\"localhost\", port=5672, username=\"admin\", password=\"123456\")\n bridge.load_services(globals()) # Automatic capture procedure of the main namespace\n async with bridge:\n await bridge.run_serve()\n\nasyncio.run(main())\n```\n\n3. Call remotely.\n```python\n# -*- coding: utf-8 -*-\n# File name: client.py\nimport asyncio\nfrom rabibridge import RMQClient\n\nasync def main():\n async with RMQClient(host=\"localhost\", port=5672, username=\"admin\", password=\"123456\") as bridge:\n err_code, result = await bridge.remote_call('fibonacci', (10, ))\n print(f\"Result is {result}\")\n # >>> Result is 55\n\nasyncio.run(main())\n```\n\n\n## Documentation\n\nFor the detailed function description, please refer to the [API reference](https://goodmanwen.github.io/RabiBridge/).\n\n[Production deployment example](https://github.com/GoodManWEN/RabiBridge/blob/main/docs/blogs/production_deployment_example.md)\n\n[Encryption in configuration file](https://github.com/GoodManWEN/RabiBridge/blob/main/docs/blogs/encryption_in_configuration_file.md)\n\n## Configuration\n\nFor production and other needs, to achieve higher convenience and stronger security, it is recommended to use configuration files instead of passing parameters. The configuration file options are as follows:\n\n```toml\n[rabbitmq] \nRABBITMQ_HOST = 'localhost' # RabbitMQ configuration info, same below.\nRABBITMQ_PORT = 5672\nRABBITMQ_USERNAME = \"admin\"\nRABBITMQ_PASSWORD = \"fMgmG7+ooAYLjXdPnhInjQ==\" # AES Encrypted, check \"Encryption in configuration file\"\n\n[app]\nDEBUG_MODE = false # Whether to run in Debug mode.\nCID_MAX = 1073741824 # The maximum value of the independent ID assigned by \n # the client for each message, which should not be \n # too small or too large.\nCOMPRESS_THRESHOLD = 1024 # Stream compression algorithm will be enabled when \n # the message size exceeds this byte threshold.\nSERIALISER = 'msgpack' # Literal['msgpack', 'pickle', 'json']\n\n[secret]\nSECRET = \"your secret that no one knows\" # Avoid being known by anyone.\n```\n\n## Performance\n\n![](https://github.com/GoodManWEN/RabiBridge/blob/main/misc/echo-performance-with-number-of-cpu-cores.png?raw=true)\n\nTesting Platform: \n```\nCPU Model : Intel(R) Xeon(R) Platinum 8369B CPU @ 2.70GHz\nCPU Cores : 16 Cores 2699.998 MHz x86_64\nCPU Cache : L2 1280K & L3 49152K\nOS : Ubuntu 22.04.4 LTS (64 Bit) KVM\nKernel : 5.15.0-106-generic\nTotal RAM : 950 MB / 30663 MB (4646 MB Buff)\nLocation : San Jose / US\nRegion : California\n```\n\n## Licence\nThe MIT License\n",
"bugtrack_url": null,
"license": null,
"summary": "A lightweight framework for service decoupling and peak shaving in web services, leveraging RabbitMQ. - GoodManWEN/RabiBridge",
"version": "0.1.2",
"project_urls": {
"Homepage": "https://github.com/GoodManWEN/RabiBridge"
},
"split_keywords": [
"rabibridge",
" rabbitmq",
" rpc",
" fastapi"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c26dfef1b7f736523d1abffb0c0f1c718e94cbcf993642c7f738581572074d17",
"md5": "ad5d57430a9bb5af9124941f5b9cf488",
"sha256": "7566db07c7184dde7c5aeba5745913de0de7ba99fa36de4d31b11dc67ed74ee9"
},
"downloads": -1,
"filename": "RabiBridge-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ad5d57430a9bb5af9124941f5b9cf488",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 20617,
"upload_time": "2024-06-01T16:29:57",
"upload_time_iso_8601": "2024-06-01T16:29:57.982094Z",
"url": "https://files.pythonhosted.org/packages/c2/6d/fef1b7f736523d1abffb0c0f1c718e94cbcf993642c7f738581572074d17/RabiBridge-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "903230767256c94d07c70df5938bb7d735902fd8099381cf245b2c89ee642d13",
"md5": "75110da312928301b30c0f25b986e6ef",
"sha256": "6ad09f14eb60a9d3d61ac097039c50ad921edf112c5e366b3723871f95eba65c"
},
"downloads": -1,
"filename": "rabibridge-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "75110da312928301b30c0f25b986e6ef",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 17482,
"upload_time": "2024-06-01T16:29:59",
"upload_time_iso_8601": "2024-06-01T16:29:59.145581Z",
"url": "https://files.pythonhosted.org/packages/90/32/30767256c94d07c70df5938bb7d735902fd8099381cf245b2c89ee642d13/rabibridge-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-01 16:29:59",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "GoodManWEN",
"github_project": "RabiBridge",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "uvicorn",
"specs": []
},
{
"name": "fastapi",
"specs": []
},
{
"name": "zstandard",
"specs": []
},
{
"name": "aio_pika",
"specs": []
},
{
"name": "psutil",
"specs": []
},
{
"name": "loguru",
"specs": []
},
{
"name": "uvloop",
"specs": []
},
{
"name": "pipeit",
"specs": []
},
{
"name": "toml",
"specs": []
},
{
"name": "cryptography",
"specs": []
},
{
"name": "msgpack",
"specs": []
}
],
"lcname": "rabibridge"
}