RabiBridge
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
- 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
- First start your rabbitmq service
docker run -d \
--name rabbitmq \
-e RABBITMQ_DEFAULT_USER=admin \
-e RABBITMQ_DEFAULT_PASS=123456 \
-p 5672:5672 \
-p 15672:15672 \
rabbitmq:management
- Import
RabiBridge, create a function to call, register and run serve.
# -*- 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())
- Call remotely.
# -*- 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.
Encryption in configuration file
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:
[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
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
Metadata
Release files for RabiBridge 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| rabibridge-0.1.2.tar.gz | 17.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| RabiBridge-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 38.1 kB
Release files / rabibridge-0.1.2.tar.gz
| Download URL | rabibridge-0.1.2.tar.gz |
|---|---|
| Size | 17.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6ad09f14eb60a9d3d61ac097039c50ad921edf112c5e366b3723871f95eba65c
|
|
BLAKE2b-256 checksum How to use checksums |
903230767256c94d07c70df5938bb7d735902fd8099381cf245b2c89ee642d13
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.3
|
Release files / RabiBridge-0.1.2-py3-none-any.whl
| Download URL | RabiBridge-0.1.2-py3-none-any.whl |
|---|---|
| Size | 20.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7566db07c7184dde7c5aeba5745913de0de7ba99fa36de4d31b11dc67ed74ee9
|
|
BLAKE2b-256 checksum How to use checksums |
c26dfef1b7f736523d1abffb0c0f1c718e94cbcf993642c7f738581572074d17
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.3
|