Skip to main content
b-rabbit-icon https://img.shields.io/pypi/v/b-rabbit.svg https://img.shields.io/travis/nidhaloff/b_rabbit.svg https://readthedocs.org/projects/b-rabbit/badge/?version=latest PyPI - Python Version PyPI - Wheel https://pepy.tech/badge/b-rabbit Twitter URL

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.

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

Release files for b-rabbit 1.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for b-rabbit 1.2.5
File Size Uploaded
b_rabbit-1.2.5.tar.gz 17.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for b-rabbit 1.2.5
File Interpreter ABI Platform
b_rabbit-1.2.5-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 26.4 kB

Release files / b_rabbit-1.2.5.tar.gz

Download URL b_rabbit-1.2.5.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ff0d0cf2c667219c5d4ccd3aee30549c51ca9c45667a0479c2631eb00a4a18b4
BLAKE2b-256 checksum
How to use checksums
0eba39057e5e6b3de80dfd4edd492ab367d1929ca967e7bde98571b0e57967a2
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / b_rabbit-1.2.5-py2.py3-none-any.whl

Download URL b_rabbit-1.2.5-py2.py3-none-any.whl
Size 9.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
55583f18eb5c3657614a96410ac37466f3456f6a2ff8ca0e6de57c328b3aab6d
BLAKE2b-256 checksum
How to use checksums
35488bc3c5f30d8f120a83b365c9914a8741e1f0db267e69bfd746b228e3ebb9
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

1.2.5 This release

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.9

2 release files

1.1.8

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.0.3

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page