soev for developers

warren.pubsub.rabbitmq.aio_pika

aio_pika-based implementation of the RabbitMQ pubsub layer.

The protocol-level configs in config describe what to set up; the modules here use aio_pika to actually do it.

aio_pika is an optional dependency: importing this sub-package without it installed raises OptionalDependencyError pointing at the warren[rmq] extra.

Classes

RMQConnectionManager

classRMQConnectionManager(config, *, name=None)
paramconfigRMQConnectionConfig
paramnamestr | None
= None
attributeconnectionAbstractRobustConnection | None

The robust connection, or None before setup().

methodsetupasync () -> None
methodteardownasync () -> None
methodcreate_channelasync () -> AbstractChannel

RMQConsumerManager

classRMQConsumerManager(config, connection_manager, consumer, *, data_publisher=None, control_publisher=None, observer_publisher=None, retry_config=None, extract_identity_func=None, publish_hard_failures=True)

RabbitMQ consumer manager that bridges message queue operations with application workers.

This class handles all RabbitMQ-specific concerns (connection management, message acknowledgment, retry logic) while delegating business logic to a worker function that remains agnostic of the underlying message transport.

The consumer receives plain dictionaries and returns optional response dictionaries—it never interacts with RabbitMQ directly.

paramconfigRMQConsumerManagerConfig
paramconnection_managerRMQConnectionManager
paramconsumerMessageConsumerInterface
paramdata_publisherPublisherInterface | None
= None
paramcontrol_publisherPublisherInterface | None
= None
paramobserver_publisherPublisherInterface | None
= None
paramretry_configRetryConfig | None
= None
paramextract_identity_funcExtractMessageIdentityFunc | None
= None
parampublish_hard_failuresbool
= True
methodsetupasync () -> None

Initialize RabbitMQ resources for consumption.

  • Sets up all publishers.
  • Creates a channel from the shared connection manager.
  • Declares the necessary exchange and queue, and binds the queue to the exchange.
  • Must be called before start_consuming().
methodstart_consumingasync () -> None

Begin consuming messages from the configured queue.

Each delivery spawns a task; handler concurrency is bounded separately from the channel prefetch.

methodstop_consumingasync () -> None

Gracefully stop message consumption and close RabbitMQ resources.

  1. Signals shutdown (stops accepting new work)
  2. Cancels the consumer (no new messages delivered)
  3. Waits for in-flight messages to complete (with timeout)
  4. Closes channel and tears down publishers
methodhealthasync (*, probe_timeout=1.0) -> ConsumerHealth

Observe transport state without touching the broker.

Reads public aio-pika surface, plus consumers on the underlying aiormq channel — a plain attribute that is not on aiormq's ABC, so its absence reads as unknown, never as lost.

paramprobe_timeoutfloat
= 1.0

RMQPublisher

classRMQPublisher(connection_manager, exchange_config, *, route=None, route_func=None, delivery_mode=2, content_type='application/json', name=None)

RabbitMQ publisher that owns its own routing decisions.

Publishes to exchange_config. A static route gives one routing key for every message. A route_func computes the routes for each message.

  • Fanout: pass neither route nor route_func, or pass a route_func. A static route raises ValueError.
  • Topic and direct: pass exactly one of route and route_func. Neither raises ValueError.
  • Both route and route_func always raise ValueError.
paramconnection_managerRMQConnectionManager
paramexchange_configRMQExchangeConfig
paramrouteRoute | None
= None
paramroute_funcRouteFunc | None
= None
paramdelivery_modeint
= 2
paramcontent_typestr
= 'application/json'
paramnamestr | None
= None

Raises:

  • ValueError: For a combination of route, route_func and exchange type that the rules above do not allow.
methodsetupasync () -> None

Open a channel and declare the publisher's exchange.

On partial failure the caller is responsible for cleanup via teardown() (idempotent, best-effort).

Raises:

  • PubSubSetupError: if the channel or exchange cannot be set up.
methodteardownasync () -> None
method__call__async (message) -> None
parammessagedict[str, Any]

Functions

declare_exchange

functiondeclare_exchangeasync (channel, config) -> AbstractExchange

Idempotently declare the exchange described by config on channel.

paramchannelAbstractChannel
paramconfigRMQExchangeConfig

Raises:

  • PubSubSetupError: if the broker rejects the declaration.

declare_queue

functiondeclare_queueasync (channel, exchange, config, *, exchange_type) -> AbstractQueue

Idempotently declare the queue described by config and bind it to exchange.

paramchannelAbstractChannel
paramexchangeAbstractExchange
paramconfigRMQQueueConfig
paramexchange_typestr

Raises:

  • PubSubSetupError: if the broker rejects the declaration or bind.

purge_queues

functionpurge_queuesasync (*, connection_manager, queue_names, exchange_name='') -> None

Delete the listed queues and optionally the exchange.

Best-effort: each deletion runs on its own channel, so failing to open a channel or to delete one entity is logged and the remaining entities are still attempted.

paramconnection_managerRMQConnectionManager

an already-setup RMQConnectionManager.

paramqueue_namesSequence[str]

queues to delete.

paramexchange_namestr
= ''

exchange to delete. Skipped when empty.

On this page