Skip to main content

A package for async communication with RabbitMQ

Project description

RabbitMQUtils

Example for reader

Consumer

from aio_rabbitmq_utils import RabbitMQConsumeInputDeviceManager, RabbitMQInputConsumeDevice


async def example():
    input_device_manager = RabbitMQConsumeInputDeviceManager(
        hosts=["the", "rabbit", "hosts", ", will", "connect", "to", "only", "one"],
        user="user",
        password="password",
        vhost="/",
        prefetch_count=10,
    )
    await input_device_manager.connect()
    input_device: RabbitMQInputConsumeDevice = await input_device_manager.get_device("some_queue_name")
    await input_device.connect()
    data, headers, transaction = await input_device.read()
    
    # do something
    
    # To ack the message (remove from queue)
    await transaction.commit()
    # To nack the message (re-queue the message)
    await transaction.rollback()

Basic Get

from aio_rabbitmq_utils import RabbitMQMultiConnectionBasicGetInputDeviceManager, RabbitMQInputBasicGetDevice


async def example():
    input_device_manager = RabbitMQMultiConnectionBasicGetInputDeviceManager(
        hosts=["the", "rabbit", "hosts", ", will", "connect", "to", "only", "one"],
        user="user",
        password="password",
        vhost="/",
        max_connections=10,
        max_channels=50,
    )
    await input_device_manager.connect()
    input_device: RabbitMQInputBasicGetDevice = await input_device_manager.get_device("some_queue_name")
    await input_device.connect()
    data, headers, transaction = await input_device.read()
    
    # do something
    
    # To ack the message (remove from queue)
    await transaction.commit()
    # To nack the message (re-queue the message)
    await transaction.rollback()

Example for writer

from io import BytesIO
from aio_rabbitmq_utils import RabbitMQOutputDeviceManager, RabbitMQOutputDevice


async def example():
    output_device_manager = RabbitMQOutputDeviceManager(
        hosts=["the", "rabbit", "hosts", ", will", "connect", "to", "only", "one"],
        user="user",
        password="password",
        vhost="/",
        exchange_name="",
    )
    await output_device_manager.connect()
    output_device: RabbitMQOutputDevice = await output_device_manager.get_device("some_routing_key")
    await output_device.connect()
    success = await output_device.send(
        BytesIO(b"Hi"),
        {"some": "headers"},
    )
    if success:
        print("Message sent")
    else:
        raise Exception("Failed to send the message")

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

aio_rabbitmq_utils-1.0.13.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

aio_rabbitmq_utils-1.0.13-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file aio_rabbitmq_utils-1.0.13.tar.gz.

File metadata

  • Download URL: aio_rabbitmq_utils-1.0.13.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for aio_rabbitmq_utils-1.0.13.tar.gz
Algorithm Hash digest
SHA256 c46d0d60415cab8b71ee8de486e6bb498d500568f928c2fa4d5a45a9d46fa339
MD5 3db86e279aeae29a446ad6f0654bfdf3
BLAKE2b-256 7beb671d2f3bbd9fb2dcfcf34a93cf8582a7c462202980097cabf9a19c4d859c

See more details on using hashes here.

File details

Details for the file aio_rabbitmq_utils-1.0.13-py3-none-any.whl.

File metadata

File hashes

Hashes for aio_rabbitmq_utils-1.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 06b2655c257f55aa4b3670dc75ef591546f2bb6a391c8b48cfbddee4f0d325ec
MD5 c0b56a1e4e0c4e23449471ac52521044
BLAKE2b-256 efabbf86abcd24437d0b22ee644554a378dc95be09d7079dc5b11092dc09a1a4

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