API

The public API of Henson-AMQP.

AMQP

class henson_amqp.AMQP(app=None)[source]

An interface to interact with an AMQP broker.

consumer()[source]

Return a new AMQP consumer.

Returns:
A new consumer object that can be used to read
from the AMQP broker and queue specified the Application’s settings.
Return type:Consumer
init_app(app)[source]

Initialize the application.

If the application’s REGISTER_CONSUMER setting is truthy, create a consumer and attach it to the application.

Parameters:app (henson.base.Application) – The application instance that will be initialized.
producer()[source]

Return an AMQP producer, creating it if necessary.

Returns:
A new producer object that can be used to write to
the AMQP broker and exchange specified by the Application’s settings.
Return type:Producer

Consumer

class henson_amqp.Consumer(app)[source]

A consumer of an AMQP queue.

Parameters:app (henson.base.Application) – The application for which this consumer consumes.
read()[source]

Read a single message from the message queue.

If the consumer has not yet begun reading from the AMQP broker, that process is initiated before yielding from the queue.

Returns:The next available message.
Return type:Message
Raises:aioamqp.exceptions.AioamqpException – The exception raised on connection close.
retry(app, message)[source]

Requeue a message to be processed again.

This coroutine is meant for use with the henson.contrib.retry.Retry extension.

Parameters:
  • app (henson.base.Application) – The application processing the message.
  • message (dict) – A copy of the message read from the AMQP server.

Note

This function assumes that messages are JSON serializeable. If they are not, a custom function may be used in its place.

Message

class henson_amqp.Message(body, envelope, properties)
body

Alias for field number 0

envelope

Alias for field number 1

properties

Alias for field number 2

Producer

class henson_amqp.Producer(app)[source]

A producer of an AMQP queue.

Parameters:app (henson.base.Application) – The application for which this producer produces.
send(message, *, routing_key=None)[source]

Send a message to the configured AMQP broker and exchange.

Parameters:
  • message (str) – The body of the message to send.
  • routing_key (str) – The routing key that should be used to send the message. If set to None, the AMQP_OUTBOUND_ROUTING_KEY application setting will be used. Defaults to None.

DeliveryMode

class henson_amqp.DeliveryMode[source]

AMQP message delivery modes.

NONPERSISTENT = 1

Mark messages as non-persistent before sending to the AMQP instance.

PERSISTENT = 2

Mark messages as persistent before sending to the AMQP instance.