An abstract interface for RabbitMQ communication
Project description
RabbitMQ without headache.
b-rabbit is a RabbitMq client library that aims to make interfacing with RabbitMQ easier. It is very useful especially inside large projects, in which many boilerplate code must be written.
I started this project when I was working on a large microservices-based project in a large team. I decided to open-source the project afterwards.
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
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
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.2.3.tar.gz
.
File metadata
- Download URL: b_rabbit-1.2.3.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3b42730f77504a83032e4e5405843832dd2f935afcd43e17b31c24148e488b1 |
|
MD5 | c70e90ef16598d101a2bcf65c6a01aa8 |
|
BLAKE2b-256 | ab61cb36f7da3a22a253f7acf644b630120e91abaaf883e7856cbbb23edc7a29 |
File details
Details for the file b_rabbit-1.2.3-py2.py3-none-any.whl
.
File metadata
- Download URL: b_rabbit-1.2.3-py2.py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbe4604a00dccfe234ec53fd2ea9ca7e89d30c77398072eb1d39cd8ea300f80d |
|
MD5 | 1957bdac2a0f6cb58b5178b2784b1b0f |
|
BLAKE2b-256 | fecc89b09cc9c01d57a59aa8a8fd32879fe82ca64cf2a3f66300a47aef84b1cb |