Skip to main content

A lightweight framework for service decoupling and peak shaving in web services, leveraging RabbitMQ. - GoodManWEN/RabiBridge

Project description

RabiBridge

fury licence pyversions Publish 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

  • 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
docker run -d \
  --name rabbitmq \
  -e RABBITMQ_DEFAULT_USER=admin \
  -e RABBITMQ_DEFAULT_PASS=123456 \
  -p 5672:5672 \
  -p 15672:15672 \
  rabbitmq:management
  1. 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())
  1. 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.

Production deployment example

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rabibridge-0.1.2.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

RabiBridge-0.1.2-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

File details

Details for the file rabibridge-0.1.2.tar.gz.

File metadata

  • Download URL: rabibridge-0.1.2.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for rabibridge-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6ad09f14eb60a9d3d61ac097039c50ad921edf112c5e366b3723871f95eba65c
MD5 75110da312928301b30c0f25b986e6ef
BLAKE2b-256 903230767256c94d07c70df5938bb7d735902fd8099381cf245b2c89ee642d13

See more details on using hashes here.

File details

Details for the file RabiBridge-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: RabiBridge-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 20.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for RabiBridge-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7566db07c7184dde7c5aeba5745913de0de7ba99fa36de4d31b11dc67ed74ee9
MD5 ad5d57430a9bb5af9124941f5b9cf488
BLAKE2b-256 c26dfef1b7f736523d1abffb0c0f1c718e94cbcf993642c7f738581572074d17

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page