Channel
- class amqpstorm.Channel[source]
RabbitMQ Channel.
e.g.
channel = connection.channel()
- property basic: Basic
RabbitMQ Basic Operations.
e.g.
message = channel.basic.get(queue='hello_world')
- Return type:
- property exchange: Exchange
RabbitMQ Exchange Operations.
e.g.
channel.exchange.declare(exchange='hello_world')
- Return type:
- property queue: Queue
RabbitMQ Queue Operations.
e.g.
channel.queue.declare(queue='hello_world')
- Return type:
- build_inbound_messages(break_on_empty: bool = False, to_tuple: bool = False, auto_decode: bool = True, message_impl: type[BaseMessage] | None = None) Iterator[Any][source]
Build messages in the inbound queue.
- Parameters:
break_on_empty (bool) –
Should we break the loop when there are no more messages in our inbound queue.
To avoid breaking out while messages are still in flight from RabbitMQ, the loop only exits after the inbound queue has been continuously empty for at least one second.
to_tuple (bool) – Should incoming messages be converted to a tuple before delivery.
auto_decode (bool) – Auto-decode strings when possible.
message_impl (class) – Optional message class to use, derived from BaseMessage, for created messages. Defaults to Message.
- Raises:
AMQPInvalidArgument – Invalid Parameters
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Return type:
generator
- close(reply_code: int = 200, reply_text: str = '') None[source]
Close Channel.
- Parameters:
- Raises:
AMQPInvalidArgument – Invalid Parameters
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Returns:
- check_for_errors() None[source]
Check connection and channel for errors.
- Raises:
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Returns:
- check_for_exceptions() None[source]
Check channel for exceptions.
- Raises:
AMQPChannelError – Raises if the channel encountered an error.
- Returns:
- confirm_deliveries() dict[str, Any][source]
Set the channel to confirm that each message has been successfully delivered.
- Raises:
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Returns:
- process_data_events(to_tuple: bool = False, auto_decode: bool = True) None[source]
Consume inbound messages.
- Parameters:
- Raises:
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Returns:
- start_consuming(to_tuple: bool = False, auto_decode: bool = True) None[source]
Start consuming messages.
- Parameters:
- Raises:
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Returns:
- stop_consuming() None[source]
Stop consuming messages.
- Raises:
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Returns:
- classmethod __new__(*args, **kwargs)
Channel.Basic
- class amqpstorm.basic.Basic[source]
RabbitMQ Basic Operations.
- qos(prefetch_count: int = 0, prefetch_size: int = 0, global_: bool = False) dict[str, Any][source]
Specify quality of service.
- Parameters:
- Raises:
AMQPInvalidArgument – Invalid Parameters
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Return type:
- get(queue: str = '', no_ack: bool = False, to_dict: bool = False, auto_decode: bool = True, message_impl: type[BaseMessage] | None = None) Message | BaseMessage | dict[str, Any] | None[source]
Fetch a single message.
- Parameters:
- Raises:
AMQPInvalidArgument – Invalid Parameters
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Returns:
Returns a single message, as long as there is a message in the queue. If no message is available, returns None.
- Return type:
- recover(requeue: bool = False) dict[str, Any][source]
Redeliver unacknowledged messages.
- Parameters:
requeue (bool) – Re-queue the messages
- Raises:
AMQPInvalidArgument – Invalid Parameters
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Return type:
- consume(callback: Callable[[...], Any] | None = None, queue: str = '', consumer_tag: str = '', exclusive: bool = False, no_ack: bool = False, no_local: bool = False, arguments: dict[str, Any] | None = None) str[source]
Start a queue consumer.
- Parameters:
- Raises:
AMQPInvalidArgument – Invalid Parameters
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Returns:
Consumer tag
- Return type:
- cancel(consumer_tag: str = '') dict[str, Any][source]
Cancel a queue consumer.
- Parameters:
consumer_tag (str) – Consumer tag
- Raises:
AMQPInvalidArgument – Invalid Parameters
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Return type:
- publish(body: bytes | str, routing_key: str, exchange: str = '', properties: dict[str, Any] | None = None, mandatory: bool = False, immediate: bool = False) bool | None[source]
Publish a Message.
- Parameters:
- Raises:
AMQPInvalidArgument – Invalid Parameters
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Return type:
bool,None
- ack(delivery_tag: int = 0, multiple: bool = False) None[source]
Acknowledge Message.
- Parameters:
delivery_tag (int/long) – Server-assigned delivery tag
multiple (bool) – Acknowledge multiple messages
- Raises:
AMQPInvalidArgument – Invalid Parameters
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Returns:
- nack(delivery_tag: int = 0, multiple: bool = False, requeue: bool = True) None[source]
Negative Acknowledgement.
- Parameters:
- Raises:
AMQPInvalidArgument – Invalid Parameters
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Returns:
- reject(delivery_tag: int = 0, requeue: bool = True) None[source]
Reject Message.
- Parameters:
delivery_tag (int/long) – Server-assigned delivery tag
requeue (bool) – Re-queue the message
- Raises:
AMQPInvalidArgument – Invalid Parameters
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Returns:
Channel.Exchange
- class amqpstorm.exchange.Exchange[source]
RabbitMQ Exchange Operations.
- declare(exchange: str = '', exchange_type: str = 'direct', passive: bool = False, durable: bool = False, auto_delete: bool = False, arguments: dict[str, Any] | None = None) dict[str, Any][source]
Declare an Exchange.
- Parameters:
- Raises:
AMQPInvalidArgument – Invalid Parameters
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Return type:
- delete(exchange: str = '', if_unused: bool = False) dict[str, Any][source]
Delete an Exchange.
- Parameters:
- Raises:
AMQPInvalidArgument – Invalid Parameters
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Return type:
- bind(destination: str = '', source: str = '', routing_key: str = '', arguments: dict[str, Any] | None = None) dict[str, Any][source]
Bind an Exchange.
- Parameters:
- Raises:
AMQPInvalidArgument – Invalid Parameters
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Return type:
- unbind(destination: str = '', source: str = '', routing_key: str = '', arguments: dict[str, Any] | None = None) dict[str, Any][source]
Unbind an Exchange.
- Parameters:
- Raises:
AMQPInvalidArgument – Invalid Parameters
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Return type:
Channel.Queue
- class amqpstorm.queue.Queue[source]
RabbitMQ Queue Operations.
- declare(queue: str = '', passive: bool = False, durable: bool = False, exclusive: bool = False, auto_delete: bool = False, arguments: dict[str, Any] | None = None) dict[str, Any][source]
Declare a Queue.
- Parameters:
- Raises:
AMQPInvalidArgument – Invalid Parameters
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Return type:
- delete(queue: str = '', if_unused: bool = False, if_empty: bool = False) dict[str, Any][source]
Delete a Queue.
- Parameters:
- Raises:
AMQPInvalidArgument – Invalid Parameters
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Return type:
- purge(queue: str) dict[str, Any][source]
Purge a Queue.
- Parameters:
queue (str) – Queue name
- Raises:
AMQPInvalidArgument – Invalid Parameters
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Return type:
- bind(queue: str = '', exchange: str = '', routing_key: str = '', arguments: dict[str, Any] | None = None) dict[str, Any][source]
Bind a Queue.
- Parameters:
- Raises:
AMQPInvalidArgument – Invalid Parameters
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Return type:
- unbind(queue: str = '', exchange: str = '', routing_key: str = '', arguments: dict[str, Any] | None = None) dict[str, Any][source]
Unbind a Queue.
- Parameters:
- Raises:
AMQPInvalidArgument – Invalid Parameters
AMQPChannelError – Raises if the channel encountered an error.
AMQPConnectionError – Raises if the connection encountered an error.
- Return type:
Channel.Tx
- class amqpstorm.tx.Tx[source]
RabbitMQ Transactions.
Server local transactions, in which the server will buffer published messages until the client commits (or rollback) the messages.
- select() dict[str, Any] | None[source]
Enable standard transaction mode.
This will enable transaction mode on the channel. Meaning that messages will be kept in the remote server buffer until such a time that either commit or rollback is called.
- Returns:
- commit() dict[str, Any] | None[source]
Commit the current transaction.
Commit all messages published during the current transaction session to the remote server.
A new transaction session starts as soon as the command has been executed.
- Returns:
- rollback() dict[str, Any] | None[source]
Abandon the current transaction.
Rollback all messages published during the current transaction session to the remote server.
Note that all messages published during this transaction session will be lost, and will have to be published again.
A new transaction session starts as soon as the command has been executed.
- Returns: