AMQP Channels
amqpy.channel.
Channel
(amqpy.abstract_channel.AbstractChannel)[source]¶Bases: amqpy.abstract_channel.AbstractChannel
The channel class provides methods for a client to establish and operate an AMQP channel. All public members are fully thread-safe.
CH_MODE_CONFIRM
= 2¶Publisher confirm mode (RabbitMQ extension)
CH_MODE_NONE
= 0¶Default channel mode
CH_MODE_TX
= 1¶Transaction mode
active
= None¶Current channel active state (flow control)
Type: | bool |
---|
is_open
= None¶Current channel open/closed state
Type: | bool |
---|
mode
= None¶Channel mode state (default, transactional, publisher confirm)
Type: | int |
---|
returned_messages
= None¶Returned messages that the server was unable to deliver
Type: | queue.Queue |
---|
__init__
(connection, channel_id=None, auto_decode=True)[source]¶Create a channel bound to a connection and using the specified numeric channel_id, and open on the server
If auto_decode is enabled (default), incoming Message bodies will be automatically decoded to str if possible.
Parameters: |
|
---|
basic_ack
(delivery_tag, multiple=False) → None[source]¶Acknowledge one or more messages
This method acknowledges one or more messages delivered via the Deliver or Get-Ok methods. The client can ask to confirm a single message or a set of messages up to and including a specific message.
Parameters: |
---|
basic_cancel
(consumer_tag, nowait=False) → None[source]¶End a queue consumer
This method cancels a consumer. This does not affect already delivered messages, but it does mean the server will not send any more messages for that consumer. The client may receive an arbitrary number of messages in between sending the cancel method and receiving the cancel-ok reply.
Parameters: |
---|
basic_consume
(queue='', consumer_tag='', no_local=False, no_ack=False, exclusive=False, nowait=False, callback=None, arguments=None, on_cancel=None) → str[source]¶Start a queue consumer
This method asks the server to start a “consumer”, which is a transient request for messages from a specific queue. Consumers last as long as the channel they were created on, or until the client cancels them.
Parameters: |
|
---|---|
Returns: | consumer tag |
Return type: |
basic_get
(queue='', no_ack=False) → amqpy.message.Message or None[source]¶Directly get a message from the queue
This method is non-blocking. If no messages are available on the queue, None is returned.
Parameters: | |
---|---|
Returns: | message, or None if no messages are available on the queue |
Return type: | amqpy.message.Message or None |
basic_publish
(msg, exchange='', routing_key='', mandatory=False, immediate=False) → None[source]¶Publish a message
This method publishes a message to a specific exchange. The message will be routed to queues as defined by the exchange configuration and distributed to any active consumers when the transaction, if any, is committed.
If publisher confirms are enabled, this method will automatically wait to receive an “ack” from the server.
Note
Returned messages are sent back from the server and loaded into the returned_messages queue of the channel that sent them. In order to receive all returned messages, call loop(0) on the connection object before checking the channel’s returned_messages queue.
Parameters: |
---|
basic_qos
(prefetch_size=0, prefetch_count=0, a_global=False) → None[source]¶Specify quality of service
This method requests a specific quality of service. The QoS can be specified for the current channel or for all channels on the connection. The particular properties and semantics of a qos method always depend on the content class semantics. Though the qos method could in principle apply to both peers, it is currently meaningful only for the server.
Parameters: |
---|
basic_recover
(requeue=False) → None[source]¶Redeliver unacknowledged messages
This method asks the broker to redeliver all unacknowledged messages on a specified channel. Zero or more messages may be redelivered. This method is only allowed on non-transacted channels.
Parameters: | requeue (bool) – if set, the server will attempt to requeue the message, potentially then delivering it to a different subscriber |
---|
basic_recover_async
(requeue=False) → None[source]¶Redeliver unacknowledged messages (async)
This method asks the broker to redeliver all unacknowledged messages on a specified channel. Zero or more messages may be redelivered. This method is only allowed on non-transacted channels.
Parameters: | requeue (bool) – if set, the server will attempt to requeue the message, potentially then delivering it to a different subscriber |
---|
basic_reject
(delivery_tag, requeue) → None[source]¶Reject an incoming message
This method allows a client to reject a message. It can be used to interrupt and cancel large incoming messages, or return untreatable messages to their original queue.
Parameters: |
---|
close
(reply_code=0, reply_text='', method_type=method_t(class_id=0, method_id=0)) → None[source]¶Request a channel close
This method indicates that the sender wants to close the channel. This may be due to internal conditions (e.g. a forced shut-down) or due to an error handling a specific method, i.e. an exception When a close is due to an exception, the sender provides the class and method id of the method which caused the exception.
Parameters: |
|
---|
confirm_select
(nowait=False) → None[source]¶Enable publisher confirms for this channel (RabbitMQ extension)
The channel must not be in transactional mode. If it is, the server raises a
PreconditionFailed
exception and closes the channel. Note that amqpy will
automatically reopen the channel, at which point this method can be called again
successfully.
Parameters: | nowait (bool) – if set, the server will not respond to the method and the client should not wait for a reply |
---|---|
Raises: | PreconditionFailed – if the channel is in transactional mode |
exchange_bind
(dest_exch, source_exch='', routing_key='', nowait=False, arguments=None) → None[source]¶Bind an exchange to an exchange
Parameters: |
|
---|
exchange_declare
(exchange, exch_type, passive=False, durable=False, auto_delete=True, nowait=False, arguments=None) → None[source]¶Declare exchange, create if needed
Parameters: |
|
---|---|
Raises: |
|
Returns: | None |
exchange_delete
(exchange, if_unused=False, nowait=False) → None[source]¶Delete an exchange
This method deletes an exchange.
Parameters: | |
---|---|
Raises: |
|
Returns: | None |
exchange_unbind
(dest_exch, source_exch='', routing_key='', nowait=False, arguments=None) → None[source]¶Unbind an exchange from an exchange
attempt to unbind an exchange that does not exist from an exchange.
Blank exchange names mean the default exchange.
Parameters: |
|
---|
flow
(active) → None[source]¶Enable/disable flow from peer
This method asks the peer to pause or restart the flow of content data. This is a simple flow-control mechanism that a peer can use to avoid overflowing its queues or otherwise finding itself receiving more messages than it can process. Note that this method is not intended for window control The peer that receives a request to stop sending content should finish sending the current content, if any, and then wait until it receives a Flow restart method.
Parameters: | active (bool) – True: peer starts sending content frames; False: peer stops sending content frames |
---|
queue_bind
(queue, exchange='', routing_key='', nowait=False, arguments=None) → None[source]¶Bind queue to an exchange
This method binds a queue to an exchange. Until a queue is bound it will not receive any messages. In a classic messaging model, store-and-forward queues are bound to a dest exchange and subscription queues are bound to a dest_wild exchange.
Parameters: |
|
---|
queue_declare
(queue='', passive=False, durable=False, exclusive=False, auto_delete=True, nowait=False, arguments=None) → queue_declare_ok_t or None[source]¶Declare queue, create if needed
This method creates or checks a queue. When creating a new queue the client can specify various properties that control the durability of the queue and its contents, and the level of sharing for the queue. A tuple containing the queue name, message count, and consumer count is returned, which is essential for declaring automatically named queues.
RabbitMQ supports the following useful additional arguments:
Parameters: |
|
---|---|
Raises: |
|
Returns: | queue_declare_ok_t(queue, message_count, consumer_count), or None if nowait |
Return type: | queue_declare_ok_t or None |
queue_delete
(queue='', if_unused=False, if_empty=False, nowait=False) → int[source]¶Delete a queue
This method deletes a queue. When a queue is deleted any pending messages are sent to a dead-letter queue if this is defined in the server configuration, and all consumers on the queue are cancelled.
Parameters: |
|
---|---|
Raises: |
|
Returns: | number of messages deleted |
Return type: |
queue_purge
(queue='', nowait=False) → int or None[source]¶Purge a queue
This method removes all messages from a queue. It does not cancel consumers. Purged messages are deleted without any formal “undo” mechanism.
Parameters: | |
---|---|
Returns: | message count (if nowait is False) |
Return type: | int or None |
queue_unbind
(queue, exchange, routing_key='', nowait=False, arguments=None) → None[source]¶Unbind a queue from an exchange
This method unbinds a queue from an exchange.
Parameters: |
|
---|
tx_commit
() → None[source]¶Commit the current transaction
This method commits all messages published and acknowledged in the current transaction. A new transaction starts immediately after a commit.
tx_rollback
() → None[source]¶Abandon the current transaction
This method abandons all messages published and acknowledged in the current transaction. A new transaction starts immediately after a rollback.
tx_select
() → None[source]¶Select standard transaction mode
This method sets the channel to use standard transactions. The client must use this method at least once on a channel before using the Commit or Rollback methods.
The channel must not be in publish acknowledge mode. If it is, the server raises a
PreconditionFailed
exception and closes the channel. Note that amqpy will
automatically reopen the channel, at which point this method can be called again
successfully.
Raises: | PreconditionFailed – if the channel is in publish acknowledge mode |
---|