This document is for Kombu's development version, which can be significantly different from previous releases. Get the stable docs here: 5.0.

Pure-python AMQP Transport - kombu.transport.pyamqp

pyamqp transport module for Kombu.

Pure-Python amqp transport using py-amqp library.

Features

  • Type: Native

  • Supports Direct: Yes

  • Supports Topic: Yes

  • Supports Fanout: Yes

  • Supports Priority: Yes

  • Supports TTL: Yes

Connection String

Connection string can have the following formats:

amqp://[USER:PASSWORD@]BROKER_ADDRESS[:PORT][/VIRTUALHOST]
[USER:PASSWORD@]BROKER_ADDRESS[:PORT][/VIRTUALHOST]
amqp://

For TLS encryption use:

amqps://[USER:PASSWORD@]BROKER_ADDRESS[:PORT][/VIRTUALHOST]

Transport Options

Transport Options are passed to constructor of underlying py-amqp Connection class.

Using TLS

Transport over TLS can be enabled by ssl parameter of Connection class. By setting ssl=True, TLS transport is used:

conn = Connect('amqp://', ssl=True)

This is equivalent to amqps:// transport URI:

conn = Connect('amqps://')

For adding additional parameters to underlying TLS, ssl parameter should be set with dict instead of True:

conn = Connect('amqp://broker.example.com', ssl={
        'keyfile': '/path/to/keyfile'
        'certfile': '/path/to/certfile',
        'ca_certs': '/path/to/ca_certfile'
    }
)

All parameters are passed to ssl parameter of amqp.connection.Connection class.

SSL option server_hostname can be set to None which is causing using hostname from broker URL. This is usefull when failover is used to fill server_hostname with currently used broker:

conn = Connect('amqp://broker1.example.com;broker2.example.com', ssl={
        'server_hostname': None
    }
)

Transport

class kombu.transport.pyamqp.Transport(client, default_port=None, default_ssl_port=None, **kwargs)[source]

AMQP Transport.

class Connection(host='localhost:5672', userid='guest', password='guest', login_method=None, login_response=None, authentication=(), virtual_host='/', locale='en_US', client_properties=None, ssl=False, connect_timeout=None, channel_max=None, frame_max=None, heartbeat=0, on_open=None, on_blocked=None, on_unblocked=None, confirm_publish=False, on_tune_ok=None, read_timeout=None, write_timeout=None, socket_settings=None, frame_handler=<function frame_handler>, frame_writer=<function frame_writer>, **kwargs)

AMQP Connection.

class Channel(connection, channel_id=None, auto_decode=True, on_open=None)

AMQP Channel.

class Message(msg, channel=None, **kwargs)

AMQP Message.

accept
body
channel
content_encoding
content_type
delivery_info
delivery_tag
headers
properties
auto_decode
channel_id
connection
is_closing
message_to_python(raw_message)

Convert encoded message body back to a Python value.

method_queue
prepare_message(body, priority=None, content_type=None, content_encoding=None, headers=None, properties=None, _Message=<class 'amqp.basic_message.Message'>)

Prepare message so that it can be sent using this transport.

prepare_queue_arguments(arguments, **kwargs)
auto_decode
channel_id
connection
is_closing
method_queue
channel_errors = (<class 'amqp.exceptions.ChannelError'>,)

Tuple of errors that can happen due to channel/method failure.

close_connection(connection)[source]

Close the AMQP broker connection.

connection_errors = (<class 'amqp.exceptions.ConnectionError'>, <class 'OSError'>, <class 'OSError'>, <class 'OSError'>)

Tuple of errors that can happen due to connection failure.

create_channel(connection)[source]
property default_connection_params
default_port = 5672

Default port used when no port has been specified.

default_ssl_port = 5671
drain_events(connection, **kwargs)[source]
driver_name = 'py-amqp'

Name of driver library (e.g. ‘py-amqp’, ‘redis’).

driver_type = 'amqp'

Type of driver, can be used to separate transports using the AMQP protocol (driver_type: ‘amqp’), Redis (driver_type: ‘redis’), etc…

driver_version()[source]
establish_connection()[source]

Establish connection to the AMQP broker.

get_heartbeat_interval(connection)[source]
get_manager(*args, **kwargs)[source]
heartbeat_check(connection, rate=2)[source]
implements = {'asynchronous': True, 'exchange_type': frozenset({'direct', 'fanout', 'headers', 'topic'}), 'heartbeats': True}
qos_semantics_matches_spec(connection)[source]
recoverable_channel_errors = (<class 'amqp.exceptions.RecoverableChannelError'>,)
recoverable_connection_errors = (<class 'amqp.exceptions.RecoverableConnectionError'>, <class 'OSError'>, <class 'OSError'>, <class 'OSError'>)
register_with_event_loop(connection, loop)[source]
verify_connection(connection)[source]

Connection

class kombu.transport.pyamqp.Connection(host='localhost:5672', userid='guest', password='guest', login_method=None, login_response=None, authentication=(), virtual_host='/', locale='en_US', client_properties=None, ssl=False, connect_timeout=None, channel_max=None, frame_max=None, heartbeat=0, on_open=None, on_blocked=None, on_unblocked=None, confirm_publish=False, on_tune_ok=None, read_timeout=None, write_timeout=None, socket_settings=None, frame_handler=<function frame_handler>, frame_writer=<function frame_writer>, **kwargs)[source]

AMQP Connection.

class Channel(connection, channel_id=None, auto_decode=True, on_open=None)

AMQP Channel.

Consumer(*args, **kwargs)
class Message(msg, channel=None, **kwargs)

AMQP Message.

exception MessageStateError

The message has already been acknowledged.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

accept
ack(multiple=False)

Acknowledge this message as being processed.

This will remove the message from the queue.

Raises

MessageStateError – If the message has already been acknowledged/requeued/rejected.

ack_log_error(logger, errors, multiple=False)
property acknowledged

Set to true if the message has been acknowledged.

body
channel
content_encoding
content_type
decode()

Deserialize the message body.

Returning the original python structure sent by the publisher.

Note

The return value is memoized, use _decode to force re-evaluation.

delivery_info
delivery_tag
errors = None
headers
property payload

The decoded message body.

properties
reject(requeue=False)

Reject this message.

The message will be discarded by the server.

Raises

MessageStateError – If the message has already been acknowledged/requeued/rejected.

reject_log_error(logger, errors, requeue=False)
requeue()

Reject this message and put it back on the queue.

Warning

You must not use this method as a means of selecting messages to process.

Raises

MessageStateError – If the message has already been acknowledged/requeued/rejected.

Producer(*args, **kwargs)
after_reply_message_received(queue)

Callback called after RPC reply received.

Notes

Reply queue semantics: can be used to delete the queue after transient reply message received.

auto_decode
basic_ack(delivery_tag, multiple=False, argsig='Lb')

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
  • delivery_tag

    longlong

    server-assigned delivery tag

    The server-assigned and channel-specific delivery tag

    RULE:

    The delivery tag is valid only within the channel from which the message was received. I.e. a client MUST NOT receive a message on one channel and then acknowledge it on another.

    RULE:

    The server MUST NOT use a zero value for delivery tags. Zero is reserved for client use, meaning “all messages so far received”.

  • multiple

    boolean

    acknowledge multiple messages

    If set to True, the delivery tag is treated as “up to and including”, so that the client can acknowledge multiple messages with a single method. If set to False, the delivery tag refers to a single message. If the multiple field is True, and the delivery tag is zero, tells the server to acknowledge all outstanding messages.

    RULE:

    The server MUST validate that a non-zero delivery- tag refers to an delivered message, and raise a channel exception if this is not the case.

basic_cancel(consumer_tag, nowait=False, argsig='sb')

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.

RULE:

If the queue no longer exists when the client sends a cancel command, or the consumer has been cancelled for other reasons, this command has no effect.

Parameters
  • consumer_tag

    shortstr

    consumer tag

    Identifier for the consumer, valid within the current connection.

    RULE:

    The consumer tag is valid only within the channel from which the consumer was created. I.e. a client MUST NOT create a consumer in one channel and then use it in another.

  • nowait

    boolean

    do not send a reply method

    If set, the server will not respond to the method. The client should not wait for a reply method. If the server could not complete the method it will raise a channel or connection exception.

basic_consume(queue='', consumer_tag='', no_local=False, no_ack=False, exclusive=False, nowait=False, callback=None, arguments=None, on_cancel=None, argsig='BssbbbbF')

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.

RULE:

The server SHOULD support at least 16 consumers per queue, unless the queue was declared as private, and ideally, impose no limit except as defined by available resources.

Parameters
  • queue

    shortstr

    Specifies the name of the queue to consume from. If the queue name is null, refers to the current queue for the channel, which is the last declared queue.

    RULE:

    If the client did not previously declare a queue, and the queue name in this method is empty, the server MUST raise a connection exception with reply code 530 (not allowed).

  • consumer_tag

    shortstr

    Specifies the identifier for the consumer. The consumer tag is local to a connection, so two clients can use the same consumer tags. If this field is empty the server will generate a unique tag.

    RULE:

    The tag MUST NOT refer to an existing consumer. If the client attempts to create two consumers with the same non-empty tag the server MUST raise a connection exception with reply code 530 (not allowed).

  • no_local

    boolean

    do not deliver own messages

    If the no-local field is set the server will not send messages to the client that published them.

  • no_ack

    boolean

    no acknowledgment needed

    If this field is set the server does not expect acknowledgments for messages. That is, when a message is delivered to the client the server automatically and silently acknowledges it on behalf of the client. This functionality increases performance but at the cost of reliability. Messages can get lost if a client dies before it can deliver them to the application.

  • exclusive

    boolean

    request exclusive access

    Request exclusive consumer access, meaning only this consumer can access the queue.

    RULE:

    If the server cannot grant exclusive access to the queue when asked, - because there are other consumers active - it MUST raise a channel exception with return code 403 (access refused).

  • nowait

    boolean

    do not send a reply method

    If set, the server will not respond to the method. The client should not wait for a reply method. If the server could not complete the method it will raise a channel or connection exception.

  • callback

    Python callable

    function/method called with each delivered message

    For each message delivered by the broker, the callable will be called with a Message object as the single argument. If no callable is specified, messages are quietly discarded, no_ack should probably be set to True in that case.

basic_get(queue='', no_ack=False, argsig='Bsb')

Direct access to a queue.

This method provides a direct access to the messages in a queue using a synchronous dialogue that is designed for specific types of application where synchronous functionality is more important than performance.

Parameters
  • queue

    shortstr

    Specifies the name of the queue to consume from. If the queue name is null, refers to the current queue for the channel, which is the last declared queue.

    RULE:

    If the client did not previously declare a queue, and the queue name in this method is empty, the server MUST raise a connection exception with reply code 530 (not allowed).

  • no_ack

    boolean

    no acknowledgment needed

    If this field is set the server does not expect acknowledgments for messages. That is, when a message is delivered to the client the server automatically and silently acknowledges it on behalf of the client. This functionality increases performance but at the cost of reliability. Messages can get lost if a client dies before it can deliver them to the application.

Non-blocking, returns a amqp.basic_message.Message object, or None if queue is empty.

basic_publish(msg, exchange='', routing_key='', mandatory=False, immediate=False, timeout=None, confirm_timeout=None, argsig='Bssbb')

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.

When channel is in confirm mode (when Connection parameter confirm_publish is set to True), each message is confirmed. When broker rejects published message (e.g. due internal broker constrains), MessageNacked exception is raised and set confirm_timeout to wait maximum confirm_timeout second for message to confirm.

Parameters
  • exchange

    shortstr

    Specifies the name of the exchange to publish to. The exchange name can be empty, meaning the default exchange. If the exchange name is specified, and that exchange does not exist, the server will raise a channel exception.

    RULE:

    The server MUST accept a blank exchange name to mean the default exchange.

    RULE:

    The exchange MAY refuse basic content in which case it MUST raise a channel exception with reply code 540 (not implemented).

  • routing_key

    shortstr

    Message routing key

    Specifies the routing key for the message. The routing key is used for routing messages depending on the exchange configuration.

  • mandatory

    boolean

    indicate mandatory routing

    This flag tells the server how to react if the message cannot be routed to a queue. If this flag is True, the server will return an unroutable message with a Return method. If this flag is False, the server silently drops the message.

    RULE:

    The server SHOULD implement the mandatory flag.

  • immediate

    boolean

    request immediate delivery

    This flag tells the server how to react if the message cannot be routed to a queue consumer immediately. If this flag is set, the server will return an undeliverable message with a Return method. If this flag is zero, the server will queue the message, but with no guarantee that it will ever be consumed.

    RULE:

    The server SHOULD implement the immediate flag.

  • timeout

    short

    timeout for publish

    Set timeout to wait maximum timeout second for message to publish.

  • confirm_timeout

    short

    confirm_timeout for publish in confirm mode

    When the channel is in confirm mode set confirm_timeout to wait maximum confirm_timeout second for message to confirm.

basic_publish_confirm(*args, **kwargs)
basic_qos(prefetch_size, prefetch_count, a_global, argsig='lBb')

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
  • prefetch_size

    long

    prefetch window in octets

    The client can request that messages be sent in advance so that when the client finishes processing a message, the following message is already held locally, rather than needing to be sent down the channel. Prefetching gives a performance improvement. This field specifies the prefetch window size in octets. The server will send a message in advance if it is equal to or smaller in size than the available prefetch size (and also falls into other prefetch limits). May be set to zero, meaning “no specific limit”, although other prefetch limits may still apply. The prefetch-size is ignored if the no-ack option is set.

    RULE:

    The server MUST ignore this setting when the client is not processing any messages - i.e. the prefetch size does not limit the transfer of single messages to a client, only the sending in advance of more messages while the client still has one or more unacknowledged messages.

  • prefetch_count

    short

    prefetch window in messages

    Specifies a prefetch window in terms of whole messages. This field may be used in combination with the prefetch-size field; a message will only be sent in advance if both prefetch windows (and those at the channel and connection level) allow it. The prefetch- count is ignored if the no-ack option is set.

    RULE:

    The server MAY send less data in advance than allowed by the client’s specified prefetch windows but it MUST NOT send more.

  • a_global

    boolean

    Defines a scope of QoS. Semantics of this parameter differs between AMQP 0-9-1 standard and RabbitMQ broker:

    MEANING IN AMQP 0-9-1:

    False: shared across all consumers on the channel True: shared across all consumers on the connection

    MEANING IN RABBITMQ:
    False: applied separately to each new consumer

    on the channel

    True: shared across all consumers on the channel

basic_recover(requeue=False)

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.

RULE:

The server MUST set the redelivered flag on all messages that are resent.

RULE:

The server MUST raise a channel exception if this is called on a transacted channel.

Parameters

requeue

boolean

requeue the message

If this field is False, the message will be redelivered to the original recipient. If this field is True, the server will attempt to requeue the message, potentially then delivering it to an alternative subscriber.

basic_recover_async(requeue=False)
basic_reject(delivery_tag, requeue, argsig='Lb')

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.

RULE:

The server SHOULD be capable of accepting and process the Reject method while sending message content with a Deliver or Get-Ok method. I.e. the server should read and process incoming methods while sending output frames. To cancel a partially-send content, the server sends a content body frame of size 1 (i.e. with no data except the frame-end octet).

RULE:

The server SHOULD interpret this method as meaning that the client is unable to process the message at this time.

RULE:

A client MUST NOT use this method as a means of selecting messages to process. A rejected message MAY be discarded or dead-lettered, not necessarily passed to another client.

Parameters
  • delivery_tag

    longlong

    server-assigned delivery tag

    The server-assigned and channel-specific delivery tag

    RULE:

    The delivery tag is valid only within the channel from which the message was received. I.e. a client MUST NOT receive a message on one channel and then acknowledge it on another.

    RULE:

    The server MUST NOT use a zero value for delivery tags. Zero is reserved for client use, meaning “all messages so far received”.

  • requeue

    boolean

    requeue the message

    If this field is False, the message will be discarded. If this field is True, the server will attempt to requeue the message.

    RULE:

    The server MUST NOT deliver the message to the same client within the context of the current channel. The recommended strategy is to attempt to deliver the message to an alternative consumer, and if that is not possible, to move the message to a dead-letter queue. The server MAY use more sophisticated tracking to hold the message on the queue and redeliver it to the same client at a later stage.

channel_id
close(reply_code=0, reply_text='', method_sig=(0, 0), argsig='BsBB')

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.

RULE:

After sending this method any received method except Channel.Close-OK MUST be discarded.

RULE:

The peer sending this method MAY use a counter or timeout to detect failure of the other peer to respond correctly with Channel.Close-OK..

Parameters
  • reply_code

    short

    The reply code. The AMQ reply codes are defined in AMQ RFC 011.

  • reply_text

    shortstr

    The localised reply text. This text can be logged as an aid to resolving issues.

  • class_id

    short

    failing method class

    When the close is provoked by a method exception, this is the class of the method.

  • method_id

    short

    failing method ID

    When the close is provoked by a method exception, this is the ID of the method.

collect()

Tear down this object.

Best called after we’ve agreed to close with the server.

confirm_select(nowait=False)

Enable publisher confirms for this channel.

Note: This is an RabbitMQ extension.

Can now be used if the channel is in transactional mode.

Parameters

nowait – If set, the server will not respond to the method. The client should not wait for a reply method. If the server could not complete the method it will raise a channel or connection exception.

connection
dispatch_method(method_sig, payload, content)
exchange_bind(destination, source='', routing_key='', nowait=False, arguments=None, argsig='BsssbF')

Bind an exchange to an exchange.

RULE:

A server MUST allow and ignore duplicate bindings - that is, two or more bind methods for a specific exchanges, with identical arguments - without treating these as an error.

RULE:

A server MUST allow cycles of exchange bindings to be created including allowing an exchange to be bound to itself.

RULE:

A server MUST not deliver the same message more than once to a destination exchange, even if the topology of exchanges and bindings results in multiple (even infinite) routes to that exchange.

Parameters
  • reserved-1 – short

  • destination

    shortstr

    Specifies the name of the destination exchange to bind.

    RULE:

    A client MUST NOT be allowed to bind a non- existent destination exchange.

    RULE:

    The server MUST accept a blank exchange name to mean the default exchange.

  • source

    shortstr

    Specifies the name of the source exchange to bind.

    RULE:

    A client MUST NOT be allowed to bind a non- existent source exchange.

    RULE:

    The server MUST accept a blank exchange name to mean the default exchange.

  • routing-key

    shortstr

    Specifies the routing key for the binding. The routing key is used for routing messages depending on the exchange configuration. Not all exchanges use a routing key - refer to the specific exchange documentation.

  • no-wait – bit

  • arguments

    table

    A set of arguments for the binding. The syntax and semantics of these arguments depends on the exchange class.

exchange_declare(exchange, type, passive=False, durable=False, auto_delete=True, nowait=False, arguments=None, argsig='BssbbbbbF')

Declare exchange, create if needed.

This method creates an exchange if it does not already exist, and if the exchange exists, verifies that it is of the correct and expected class.

RULE:

The server SHOULD support a minimum of 16 exchanges per virtual host and ideally, impose no limit except as defined by available resources.

Parameters
  • exchange

    shortstr

    RULE:

    Exchange names starting with “amq.” are reserved for predeclared and standardised exchanges. If the client attempts to create an exchange starting with “amq.”, the server MUST raise a channel exception with reply code 403 (access refused).

  • type

    shortstr

    exchange type

    Each exchange belongs to one of a set of exchange types implemented by the server. The exchange types define the functionality of the exchange - i.e. how messages are routed through it. It is not valid or meaningful to attempt to change the type of an existing exchange.

    RULE:

    If the exchange already exists with a different type, the server MUST raise a connection exception with a reply code 507 (not allowed).

    RULE:

    If the server does not support the requested exchange type it MUST raise a connection exception with a reply code 503 (command invalid).

  • passive

    boolean

    do not create exchange

    If set, the server will not create the exchange. The client can use this to check whether an exchange exists without modifying the server state.

    RULE:

    If set, and the exchange does not already exist, the server MUST raise a channel exception with reply code 404 (not found).

  • durable

    boolean

    request a durable exchange

    If set when creating a new exchange, the exchange will be marked as durable. Durable exchanges remain active when a server restarts. Non-durable exchanges (transient exchanges) are purged if/when a server restarts.

    RULE:

    The server MUST support both durable and transient exchanges.

    RULE:

    The server MUST ignore the durable field if the exchange already exists.

  • auto_delete

    boolean

    auto-delete when unused

    If set, the exchange is deleted when all queues have finished using it.

    RULE:

    The server SHOULD allow for a reasonable delay between the point when it determines that an exchange is not being used (or no longer used), and the point when it deletes the exchange. At the least it must allow a client to create an exchange and then bind a queue to it, with a small but non-zero delay between these two actions.

    RULE:

    The server MUST ignore the auto-delete field if the exchange already exists.

  • nowait

    boolean

    do not send a reply method

    If set, the server will not respond to the method. The client should not wait for a reply method. If the server could not complete the method it will raise a channel or connection exception.

  • arguments

    table

    arguments for declaration

    A set of arguments for the declaration. The syntax and semantics of these arguments depends on the server implementation. This field is ignored if passive is True.

exchange_delete(exchange, if_unused=False, nowait=False, argsig='Bsbb')

Delete an exchange.

This method deletes an exchange. When an exchange is deleted all queue bindings on the exchange are cancelled.

Parameters
  • exchange

    shortstr

    RULE:

    The exchange MUST exist. Attempting to delete a non-existing exchange causes a channel exception.

  • if_unused

    boolean

    delete only if unused

    If set, the server will only delete the exchange if it has no queue bindings. If the exchange has queue bindings the server does not delete it but raises a channel exception instead.

    RULE:

    If set, the server SHOULD delete the exchange but only if it has no queue bindings.

    RULE:

    If set, the server SHOULD raise a channel exception if the exchange is in use.

  • nowait

    boolean

    do not send a reply method

    If set, the server will not respond to the method. The client should not wait for a reply method. If the server could not complete the method it will raise a channel or connection exception.

exchange_unbind(destination, source='', routing_key='', nowait=False, arguments=None, argsig='BsssbF')

Unbind an exchange from an exchange.

RULE:

If a unbind fails, the server MUST raise a connection exception.

Parameters
  • reserved-1 – short

  • destination

    shortstr

    Specifies the name of the destination exchange to unbind.

    RULE:

    The client MUST NOT attempt to unbind an exchange that does not exist from an exchange.

    RULE:

    The server MUST accept a blank exchange name to mean the default exchange.

  • source

    shortstr

    Specifies the name of the source exchange to unbind.

    RULE:

    The client MUST NOT attempt to unbind an exchange from an exchange that does not exist.

    RULE:

    The server MUST accept a blank exchange name to mean the default exchange.

  • routing-key

    shortstr

    Specifies the routing key of the binding to unbind.

  • no-wait – bit

  • arguments

    table

    Specifies the arguments of the binding to unbind.

flow(active)

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.

RULE:

When a new channel is opened, it is active. Some applications assume that channels are inactive until started. To emulate this behaviour a client MAY open the channel, then pause it.

RULE:

When sending content data in multiple frames, a peer SHOULD monitor the channel for incoming methods and respond to a Channel.Flow as rapidly as possible.

RULE:

A peer MAY use the Channel.Flow method to throttle incoming content data for internal reasons, for example, when exchanging data over a slower connection.

RULE:

The peer that requests a Channel.Flow method MAY disconnect and/or ban a peer that does not respect the request.

Parameters

active

boolean

start/stop content frames

If True, the peer starts sending content frames. If False, the peer stops sending content frames.

get_bindings()
is_closing
message_to_python(raw_message)

Convert encoded message body back to a Python value.

method_queue
no_ack_consumers = None
open()

Open a channel for use.

This method opens a virtual connection (a channel).

RULE:

This method MUST NOT be called when the channel is already open.

Parameters

out_of_band

shortstr (DEPRECATED)

out-of-band settings

Configures out-of-band transfers on this channel. The syntax and meaning of this field will be formally defined at a later date.

prepare_message(body, priority=None, content_type=None, content_encoding=None, headers=None, properties=None, _Message=<class 'amqp.basic_message.Message'>)

Prepare message so that it can be sent using this transport.

prepare_queue_arguments(arguments, **kwargs)
queue_bind(queue, exchange='', routing_key='', nowait=False, arguments=None, argsig='BsssbF')

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.

RULE:

A server MUST allow ignore duplicate bindings - that is, two or more bind methods for a specific queue, with identical arguments - without treating these as an error.

RULE:

If a bind fails, the server MUST raise a connection exception.

RULE:

The server MUST NOT allow a durable queue to bind to a transient exchange. If the client attempts this the server MUST raise a channel exception.

RULE:

Bindings for durable queues are automatically durable and the server SHOULD restore such bindings after a server restart.

RULE:

The server SHOULD support at least 4 bindings per queue, and ideally, impose no limit except as defined by available resources.

Parameters
  • queue

    shortstr

    Specifies the name of the queue to bind. If the queue name is empty, refers to the current queue for the channel, which is the last declared queue.

    RULE:

    If the client did not previously declare a queue, and the queue name in this method is empty, the server MUST raise a connection exception with reply code 530 (not allowed).

    RULE:

    If the queue does not exist the server MUST raise a channel exception with reply code 404 (not found).

  • exchange

    shortstr

    The name of the exchange to bind to.

    RULE:

    If the exchange does not exist the server MUST raise a channel exception with reply code 404 (not found).

  • routing_key

    shortstr

    message routing key

    Specifies the routing key for the binding. The routing key is used for routing messages depending on the exchange configuration. Not all exchanges use a routing key - refer to the specific exchange documentation. If the routing key is empty and the queue name is empty, the routing key will be the current queue for the channel, which is the last declared queue.

  • nowait

    boolean

    do not send a reply method

    If set, the server will not respond to the method. The client should not wait for a reply method. If the server could not complete the method it will raise a channel or connection exception.

  • arguments

    table

    arguments for binding

    A set of arguments for the binding. The syntax and semantics of these arguments depends on the exchange class.

queue_declare(queue='', passive=False, durable=False, exclusive=False, auto_delete=True, nowait=False, arguments=None, argsig='BsbbbbbF')

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.

RULE:

The server MUST create a default binding for a newly- created queue to the default exchange, which is an exchange of type ‘direct’.

RULE:

The server SHOULD support a minimum of 256 queues per virtual host and ideally, impose no limit except as defined by available resources.

Parameters
  • queue

    shortstr

    RULE:

    The queue name MAY be empty, in which case the server MUST create a new queue with a unique generated name and return this to the client in the Declare-Ok method.

    RULE:

    Queue names starting with “amq.” are reserved for predeclared and standardised server queues. If the queue name starts with “amq.” and the passive option is False, the server MUST raise a connection exception with reply code 403 (access refused).

  • passive

    boolean

    do not create queue

    If set, the server will not create the queue. The client can use this to check whether a queue exists without modifying the server state.

    RULE:

    If set, and the queue does not already exist, the server MUST respond with a reply code 404 (not found) and raise a channel exception.

  • durable

    boolean

    request a durable queue

    If set when creating a new queue, the queue will be marked as durable. Durable queues remain active when a server restarts. Non-durable queues (transient queues) are purged if/when a server restarts. Note that durable queues do not necessarily hold persistent messages, although it does not make sense to send persistent messages to a transient queue.

    RULE:

    The server MUST recreate the durable queue after a restart.

    RULE:

    The server MUST support both durable and transient queues.

    RULE:

    The server MUST ignore the durable field if the queue already exists.

  • exclusive

    boolean

    request an exclusive queue

    Exclusive queues may only be consumed from by the current connection. Setting the ‘exclusive’ flag always implies ‘auto-delete’.

    RULE:

    The server MUST support both exclusive (private) and non-exclusive (shared) queues.

    RULE:

    The server MUST raise a channel exception if ‘exclusive’ is specified and the queue already exists and is owned by a different connection.

  • auto_delete

    boolean

    auto-delete queue when unused

    If set, the queue is deleted when all consumers have finished using it. Last consumer can be cancelled either explicitly or because its channel is closed. If there was no consumer ever on the queue, it won’t be deleted.

    RULE:

    The server SHOULD allow for a reasonable delay between the point when it determines that a queue is not being used (or no longer used), and the point when it deletes the queue. At the least it must allow a client to create a queue and then create a consumer to read from it, with a small but non-zero delay between these two actions. The server should equally allow for clients that may be disconnected prematurely, and wish to re- consume from the same queue without losing messages. We would recommend a configurable timeout, with a suitable default value being one minute.

    RULE:

    The server MUST ignore the auto-delete field if the queue already exists.

  • nowait

    boolean

    do not send a reply method

    If set, the server will not respond to the method. The client should not wait for a reply method. If the server could not complete the method it will raise a channel or connection exception.

  • arguments

    table

    arguments for declaration

    A set of arguments for the declaration. The syntax and semantics of these arguments depends on the server implementation. This field is ignored if passive is True.

Returns a tuple containing 3 items:

the name of the queue (essential for automatically-named queues), message count and consumer count

queue_delete(queue='', if_unused=False, if_empty=False, nowait=False, argsig='Bsbbb')

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.

RULE:

The server SHOULD use a dead-letter queue to hold messages that were pending on a deleted queue, and MAY provide facilities for a system administrator to move these messages back to an active queue.

Parameters
  • queue

    shortstr

    Specifies the name of the queue to delete. If the queue name is empty, refers to the current queue for the channel, which is the last declared queue.

    RULE:

    If the client did not previously declare a queue, and the queue name in this method is empty, the server MUST raise a connection exception with reply code 530 (not allowed).

    RULE:

    The queue must exist. Attempting to delete a non- existing queue causes a channel exception.

  • if_unused

    boolean

    delete only if unused

    If set, the server will only delete the queue if it has no consumers. If the queue has consumers the server does does not delete it but raises a channel exception instead.

    RULE:

    The server MUST respect the if-unused flag when deleting a queue.

  • if_empty

    boolean

    delete only if empty

    If set, the server will only delete the queue if it has no messages. If the queue is not empty the server raises a channel exception.

  • nowait

    boolean

    do not send a reply method

    If set, the server will not respond to the method. The client should not wait for a reply method. If the server could not complete the method it will raise a channel or connection exception.

If nowait is False, returns the number of deleted messages.

queue_purge(queue='', nowait=False, argsig='Bsb')

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.

RULE:

A call to purge MUST result in an empty queue.

RULE:

On transacted channels the server MUST not purge messages that have already been sent to a client but not yet acknowledged.

RULE:

The server MAY implement a purge queue or log that allows system administrators to recover accidentally-purged messages. The server SHOULD NOT keep purged messages in the same storage spaces as the live messages since the volumes of purged messages may get very large.

Parameters
  • queue

    shortstr

    Specifies the name of the queue to purge. If the queue name is empty, refers to the current queue for the channel, which is the last declared queue.

    RULE:

    If the client did not previously declare a queue, and the queue name in this method is empty, the server MUST raise a connection exception with reply code 530 (not allowed).

    RULE:

    The queue must exist. Attempting to purge a non- existing queue causes a channel exception.

  • nowait

    boolean

    do not send a reply method

    If set, the server will not respond to the method. The client should not wait for a reply method. If the server could not complete the method it will raise a channel or connection exception.

If nowait is False, returns a number of purged messages.

queue_unbind(queue, exchange, routing_key='', nowait=False, arguments=None, argsig='BsssF')

Unbind a queue from an exchange.

This method unbinds a queue from an exchange.

RULE:

If a unbind fails, the server MUST raise a connection exception.

Parameters
  • queue

    shortstr

    Specifies the name of the queue to unbind.

    RULE:

    The client MUST either specify a queue name or have previously declared a queue on the same channel

    RULE:

    The client MUST NOT attempt to unbind a queue that does not exist.

  • exchange

    shortstr

    The name of the exchange to unbind from.

    RULE:

    The client MUST NOT attempt to unbind a queue from an exchange that does not exist.

    RULE:

    The server MUST accept a blank exchange name to mean the default exchange.

  • routing_key

    shortstr

    routing key of binding

    Specifies the routing key of the binding to unbind.

  • arguments

    table

    arguments of binding

    Specifies the arguments of the binding to unbind.

send_method(sig, format=None, args=None, content=None, wait=None, callback=None, returns_tuple=False)
then(on_success, on_error=None)
tx_commit()

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()

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()

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.

wait(method, callback=None, timeout=None, returns_tuple=False)
Transport(host, connect_timeout, ssl=False, read_timeout=None, write_timeout=None, socket_settings=None, **kwargs)[source]
auto_decode
blocking_read(timeout=None)[source]
bytes_recv = 0

Number of successful reads from socket.

bytes_sent = 0

Number of successful writes to socket.

channel(channel_id=None, callback=None)[source]

Create new channel.

Fetch a Channel object identified by the numeric channel_id, or create that object if it doesn’t already exist.

channel_errors = (<class 'amqp.exceptions.ChannelError'>,)
channel_id
client_heartbeat = None

Original heartbeat interval value proposed by client.

close(reply_code=0, reply_text='', method_sig=(0, 0), argsig='BsBB')[source]

Request a connection close.

This method indicates that the sender wants to close the connection. 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.

RULE:

After sending this method any received method except the Close-OK method MUST be discarded.

RULE:

The peer sending this method MAY use a counter or timeout to detect failure of the other peer to respond correctly with the Close-OK method.

RULE:

When a server receives the Close method from a client it MUST delete all server-side resources associated with the client’s context. A client CANNOT reconnect to a context after sending or receiving a Close method.

Parameters
  • reply_code

    short

    The reply code. The AMQ reply codes are defined in AMQ RFC 011.

  • reply_text

    shortstr

    The localised reply text. This text can be logged as an aid to resolving issues.

  • class_id

    short

    failing method class

    When the close is provoked by a method exception, this is the class of the method.

  • method_id

    short

    failing method ID

    When the close is provoked by a method exception, this is the ID of the method.

collect()[source]
connect(callback=None)[source]
property connected
connection
connection_errors = (<class 'amqp.exceptions.ConnectionError'>, <class 'OSError'>, <class 'OSError'>, <class 'OSError'>)
dispatch_method(method_sig, payload, content)
drain_events(timeout=None)[source]
property frame_writer
heartbeat = None

Final heartbeat interval value (in float seconds) after negotiation

heartbeat_tick(rate=2)[source]

Send heartbeat packets if necessary.

Raises

ConnectionForvced – if none have been received recently.

Note

This should be called frequently, on the order of once per second.

Keyword Arguments

rate (int) – Previously used, but ignored now.

is_alive()[source]
is_closing
last_heartbeat_received = 0

Time of last heartbeat received (in monotonic time, if available).

last_heartbeat_sent = 0

Time of last heartbeat sent (in monotonic time, if available).

library_properties = {'product': 'py-amqp', 'product_version': '5.1.0'}

These are sent to the server to announce what features we support, type of client etc.

method_queue
negotiate_capabilities = {'authentication_failure_close': True, 'connection.blocked': True, 'consumer_cancel_notify': True}

Mapping of protocol extensions to enable. The server will report these in server_properties[capabilities], and if a key in this map is present the client will tell the server to either enable or disable the capability depending on the value set in this map. For example with:

negotiate_capabilities = {

‘consumer_cancel_notify’: True,

}

The client will enable this capability if the server reports support for it, but if the value is False the client will disable the capability.

property on_inbound_frame
on_inbound_method(channel_id, method_sig, payload, content)[source]
prev_recv = None

Number of bytes received from socket at the last heartbeat check.

prev_sent = None

Number of bytes sent to socket at the last heartbeat check.

recoverable_channel_errors = (<class 'amqp.exceptions.RecoverableChannelError'>,)
recoverable_connection_errors = (<class 'amqp.exceptions.RecoverableConnectionError'>, <class 'OSError'>, <class 'OSError'>, <class 'OSError'>)
send_heartbeat()[source]
send_method(sig, format=None, args=None, content=None, wait=None, callback=None, returns_tuple=False)
property server_capabilities
server_heartbeat = None

Original heartbeat interval proposed by server.

property sock
then(on_success, on_error=None)[source]
property transport
wait(method, callback=None, timeout=None, returns_tuple=False)

Channel

class kombu.transport.pyamqp.Channel(connection, channel_id=None, auto_decode=True, on_open=None)[source]

AMQP Channel.

class Message(msg, channel=None, **kwargs)

AMQP Message.

accept
body
channel
content_encoding
content_type
delivery_info
delivery_tag
headers
properties
auto_decode
channel_id
connection
is_closing
message_to_python(raw_message)[source]

Convert encoded message body back to a Python value.

method_queue
prepare_message(body, priority=None, content_type=None, content_encoding=None, headers=None, properties=None, _Message=<class 'amqp.basic_message.Message'>)[source]

Prepare message so that it can be sent using this transport.

prepare_queue_arguments(arguments, **kwargs)[source]

Message

class kombu.transport.pyamqp.Message(msg, channel=None, **kwargs)[source]

AMQP Message.

accept
body
channel
content_encoding
content_type
delivery_info
delivery_tag
headers
properties