pika-based RabbitMQ connector with built in JSON serialization/deserialization
Project description
rabbitqm-alphamoon
pika-based RabbitMQ connector with built in JSON serialization/deserialization
Features
- publishing:
publish(message)
- getting number of messages in the queue:
message_count
- consuming (forever, i.e. with a callback function):
consume_forever(callback_fun)
- setting up a dead letter exchange (number of retries passed to the consumer in the
info
argument)
See code examples in the "Examples" section.
Requirements
pika==1.2.0
Installation
You can install "rabbitmq-alphamoon" via pip from PyPI:
$ pip install rabbitmq-alphamoon
Examples
Initialization
import pika
from rabbitmq_alphamoon import RabbitMQConnector
parameters = pika.ConnectionParameters(
host=rabbitmq_host,
port=rabbitmq_port,
credentials=pika.PlainCredentials(
username=rabbitmq_username,
password=rabbitmq_password,
),
)
queue = RabbitMQConnector(
connection_parameters=parameters,
queue=queue_name,
)
Publishing
message = {'foo': 'bar'}
with queue.open_connection():
queue.publish(message)
Getting a number of the messages in the queue
message_count = queue.message_count
Consuming
def process_message(message, info):
print(message)
print(info)
with queue.open_connection():
queue.consume_forever(process_message_callback=process_message)
Short form for one-time usage of connector
If you do not need to reuse the connector, you can initialize and open connection without assignment of connector to a variable before calling open_connection
context manager. This may come in handy especially in case of consuming, where connector is usually used only to call consume_forever
function.
with RabbitMQConnector(
connection_parameters=parameters,
queue=queue_name,
).open_connection() as queue:
queue.consume_forever(process_message_callback=process_message)
Contributing
Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.
License
Distributed under the terms of the MIT license, "rabbitmq-alphamoon" is free and open source software
Issues
If you encounter any problems, please email us at dev@alphamoon.ai, along with a detailed description.
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
Hashes for rabbitmq_alphamoon-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50f6b58426d893f3c37effcd31fc26a7b0886459d149ce36089e474a5e692507 |
|
MD5 | f81c850f7d3ebdd4f8fd1d915668b962 |
|
BLAKE2b-256 | 3cb1608ad12a1489a5dcbe1af57008b0c87e623fdc38637156e04b8af03b8da9 |