Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

philiarabbit-0.1.4.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philiarabbit-0.1.4-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file philiarabbit-0.1.4.tar.gz.

File metadata

  • Download URL: philiarabbit-0.1.4.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.11.0-17-generic

File hashes

Hashes for philiarabbit-0.1.4.tar.gz
Algorithm Hash digest
SHA256 5c00751029464a239a90856b173e4e5c4a58eaa152a3958bd96db5ffe99df831
MD5 c300922b4cff8cbbb55f1fa6b4550a8a
BLAKE2b-256 09fa067ab6bfaa36f6d0e6a5eb51c466b974d6717a1a5ac4c8177b1439212869

See more details on using hashes here.

File details

Details for the file philiarabbit-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: philiarabbit-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.11.0-17-generic

File hashes

Hashes for philiarabbit-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1aa3097a86cfe30ef0c612f41330d8363720c2c9b478d4b084912ac3732e9ed5
MD5 5d534213be9e136a4d01c0059abbf708
BLAKE2b-256 174dac4e1cf5d95569eb37dd717762ba6622e229e7a80f539c7434c0050dad24

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page