High level interfaces for work with RabbitMQ.
Project description
Stack:
Installation
pip install rabbitmq-clients
Usage
Run rabbitMQ on your computer.
Producer
import asyncio
import json
from rabbitmq_clients import RabbitProducer
if __name__ == "__main__":
producer = RabbitProducer(
host='localhost',
login='test',
password='test',
queue_name='test_queue',
exchange_name='',
routing_key='',
)
data = {"result": True}
asyncio.run(producer.publish(json.dumps(data)))
Consume multiply queues (recommended)
import asyncio
from rabbitmq_clients import RabbitConsumer, QueueDTO
from rabbitmq_clients.core.types import JSON
async def show_decoded_result(result: JSON):
print(result)
async def show_encoded_result(result: JSON):
print(result.body)
if __name__ == "__main__":
consumer = RabbitConsumer(
host='localhost',
login='test',
password='test',
queue_name='decoded_result',
)
first_queue = QueueDTO(
name='test_queue',
callback=show_decoded_result,
)
second_queue = QueueDTO(
name='encoded_result',
callback=show_encoded_result,
auto_decode=False,
)
consumer.add_queue(first_queue)
consumer.add_queue(second_queue)
try:
asyncio.run(consumer.consume_all())
except KeyboardInterrupt:
pass
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
rabbitmq_clients-0.1.9.tar.gz
(5.3 kB
view hashes)
Built Distribution
Close
Hashes for rabbitmq_clients-0.1.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a29010742e088bf7d8ef674fb07386687c6c44a41f3f1b56327ece6809fa7e91 |
|
MD5 | b76a54606e6593096e04e539dbe82870 |
|
BLAKE2b-256 | e03d7e2f6651b177202d0087509f459ffe010a6211e0be0993cf9f54f3c8bf7f |