Skip to content

Consumer

RabbitMQConsumer

Bases: BaseRabbitMQ

A RabbitMQ consumer class that extends BaseRabbitMQ.

Methods:

Name Description
__init__

Initialize the RabbitMQConsumer object.

listen

Asynchronously listen to a queue and call the callback function on message arrival.

Source code in libs/python/resources/py-rabbitmq/pyrabbitmq/consumer.py
class RabbitMQConsumer(BaseRabbitMQ):
    """A RabbitMQ consumer class that extends BaseRabbitMQ.

    Args:
        None

    Attributes:
        None

    Methods:
        __init__: Initialize the RabbitMQConsumer object.
        listen: Asynchronously listen to a queue and call the callback function on message arrival.

    """
    def __init__(self):
        super().__init__()

    async def listen(self, queue: aio_pika.Queue, callback: callable) -> None:
        """Listen to a RabbitMQ queue and call the specified callback on message arrival.

        Args:
            queue (aio_pika.Queue): The queue to listen to.
            callback (callable): The callback function to execute on message arrival.

        Returns:
            None

        """
        async with queue.iterator() as queue_iter:
            message: aio_pika.AbstractIncomingMessage
            async for message in queue_iter:
                await callback(message)

listen(queue, callback) async

Listen to a RabbitMQ queue and call the specified callback on message arrival.

Parameters:

Name Type Description Default
queue Queue

The queue to listen to.

required
callback callable

The callback function to execute on message arrival.

required

Returns:

Type Description
None

None

Source code in libs/python/resources/py-rabbitmq/pyrabbitmq/consumer.py
async def listen(self, queue: aio_pika.Queue, callback: callable) -> None:
    """Listen to a RabbitMQ queue and call the specified callback on message arrival.

    Args:
        queue (aio_pika.Queue): The queue to listen to.
        callback (callable): The callback function to execute on message arrival.

    Returns:
        None

    """
    async with queue.iterator() as queue_iter:
        message: aio_pika.AbstractIncomingMessage
        async for message in queue_iter:
            await callback(message)