An abstract interface for RabbitMQ communication
Project description
RabbitMQ without headache.
b_rabbit is a RabbitMq Interface on top of rabbitpy to make implementing RabbitMQ messaging patterns easier. It is very useful especially inside large projects, in which many boilerplate code must be written. it uses a parent wrapper class that wrap all connections and classes definitions of different messaging patterns, then using the patterns is pretty straightforward by creating instances from the parent class depending on the pattern you want to use. it uses multithreading to asynchronously orchestrate between multiple subscription and RPCs.
Free software: MIT license
Documentation: https://b_rabbit.readthedocs.io.
Features
it implements all RabbitMQ messaging patterns.
provides an easy high level API (take a look at the examples)
thread safe since it uses rabbitpy
implementation of the publish-subscribe pattern
implementation of the Remote procedure call pattern
safe message delivery
When you should use it
if you are having problems with other non thread safe libraries (like I did)
if you want to develop fast by using a high level API
if you don’t want to write much code and save much time
if you want to use multithreading
if you want to get started with RabbitMQ
Why you should use it
High level of abstraction
Simple syntax and readability improvement
Scalablity (since it uses multiple channels but only one connection)
Asynchronous fast messaging
Code reusability
Quick Usage
import the library:
from b_rabbit import BRabbit
create a parent instance which provide a global rabbitMQ connection
rabbit = BRabbit(host='localhost', port=5672)
now, just one liner to publish a message:
publisher = rabbit.EventPublisher(b_rabbit=rabbit,
publisher_name='pub').publish(routing_key='testing.test',
payload='Hello from publisher')
or if you want to subscribe and listen to a certain topic:
def callback(msg):
# do something with the received msg from the publisher
print(f"msg received: {msg}")
# subscribe and run a listener in a thread
subscriber = rabbit.EventSubscriber(
b_rabbit=rabbit,
routing_key='testing.test',
publisher_name='pub',
event_listener=callback).subscribe_on_thread()
Advanced Usage using RPC
task requester
from b_rabbit import BRabbit
def taskResponseListener(body):
print('Task Response received')
print(str(body))
rabbit = BRabbit(host='localhost', port=5672)
taskRequesterSynchron = rabbit.TaskRequesterSynchron(b_rabbit=rabbit,
executor_name='test',
routing_key='testing.test',
response_listener=taskResponseListener)
taskRequesterSynchron.request_task('msg from requester')
rabbit.close_connection()
task responser (server)
from b_rabbit import BRabbit
import time
rabbit = BRabbit(host='localhost', port=5672)
def taskListener(server, body):
print('Task Request received')
print(str(body))
time.sleep(5)
server.send_return(payload="return this value to requester")
taskExecuter = rabbit.TaskExecutor(b_rabbit=rabbit,
executor_name='test',
routing_key='testing.test',
task_listener=taskListener).run_task_on_thread()
Further
Take a look in the examples folder for more. b_rabbit implements also the remote procedure call (RPC) pattern
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file b_rabbit-1.1.4.tar.gz
.
File metadata
- Download URL: b_rabbit-1.1.4.tar.gz
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ecd9b7ebf2ce22968556653520be092b928f3c51344845290b937b7fe6f4029 |
|
MD5 | 28f4293ffd6e73feab293a7cc8bf8d03 |
|
BLAKE2b-256 | ef25fcced301bb9d2e902ef7067353e18439a452d25a0269fe1b7d061b712232 |
File details
Details for the file b_rabbit-1.1.4-py2.py3-none-any.whl
.
File metadata
- Download URL: b_rabbit-1.1.4-py2.py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e024a1cb27fb6c0e92a34d023ae305f972fadc5ab1b0087f1c8e54e9d5da1d21 |
|
MD5 | dc596e142f05ea0e47bfb36a4d787289 |
|
BLAKE2b-256 | df55a98feb2db652e38fcc47b314fbc6db658be5592d6c37201b1f55ca2c6af2 |