No project description provided
Project description
Documentation:
https://github.com/AmirRedHat/PhiliaRabbitMQ
Description
This project made for philia. In this project we package the rabbitmq utils.
- producer
- consumer
- connection pool
Consumer
The consumer implemented in two version (sync and async).
Both of them accept an callback function as argument and received data from producer
will pass to callback
Sync Version :
def consumer_callback(ch, method, properties, body):
...
# body is received data from producer
from philiarabbit.consumer import PhiliaRabbitConsumer
from pika.exchange_type import ExchangeType
consumer = PhiliaRabbitConsumer(
rabbit_url="",
queue_name="",
exchange_name="",
routing_keys=[],
exchange_type=ExchangeType.topic # TOPIC or DIRECT
)
consumer.run(consumer_callback)
Async Version :
async def consumer_callback(body):
...
# body is received data from producer
from philiarabbit.consumer import AsyncPhiliaRabbitConsumer
import aio_pika
import asyncio
consumer = AsyncPhiliaRabbitConsumer(
rabbit_url="",
queue_name="",
exchange_name="",
routing_keys=[],
exchange_type=aio_pika.ExchangeType.TOPIC # TOPIC or DIRECT
)
asyncio.run(consumer.run(consumer_callback))
Producer
The producer is implemented in two version (sync and async). just define exchange_name and routing_key then publish the message. you can also manage the connections by passing connection pool object.
Connection Pool
The connection pool is implemented in two version (sync and async). This class will manage your rabbitmq connections and keep them in queue for heavy-call cases
Example :
from philiarabbit.connection_pool import PhiliaRabbitConnectionPool
pool = PhiliaRabbitConnectionPool(
rabbit_url="",
max_size=2,
logger=None # you can pass a logger instance
)
connection, channel = pool.get_connection_with_channel()
# you can use the connection and channel in your codebase
Example of connection pool with producer :
from philiarabbit.connection_pool import PhiliaRabbitConnectionPool
pool = PhiliaRabbitConnectionPool(
rabbit_url="",
max_size=2,
logger=None # you can pass a logger instance
)
from philiarabbit.producer import PhiliaRabbitProducer
producer = PhiliaRabbitProducer(
rabbit_url="",
routing_key="",
exchange_name="",
)
producer.publish(data=bytes)
Test
The integration tests wrote in /tests/ directory.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file philiarabbit-0.1.6.tar.gz.
File metadata
- Download URL: philiarabbit-0.1.6.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.14.0-29-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10e509739e177454d2923aaaf9173659c84f99570a0f26611bbb4abfde924609
|
|
| MD5 |
ff7bdfd435660003d62189b8ca364a4c
|
|
| BLAKE2b-256 |
e3d8e948075cacd3eb65ac6c0fe9ffa9af759b5665a176509fa3f743bf3c5326
|
File details
Details for the file philiarabbit-0.1.6-py3-none-any.whl.
File metadata
- Download URL: philiarabbit-0.1.6-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.14.0-29-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c05ef541217cb66a744b714518df3e8598983c8b8efc942763deeda6972685c3
|
|
| MD5 |
f144338509fb7892b745cce014349b91
|
|
| BLAKE2b-256 |
485e0168284871e621ee30fe9104cbb0de34dbce6d330cf7f87718045a20fb05
|