This document describes Celery 2.4. For development docs, go here.


class celery.backends.amqp.AMQPBackend(connection=None, exchange=None, exchange_type=None, persistent=None, serializer=None, auto_delete=True, **kwargs)

Publishes results by sending messages.

exception BacklogLimitExceeded

Too much state history to fast-forward.

class AMQPBackend.Consumer(channel, queues=None, no_ack=None, auto_declare=None, callbacks=None, on_decode_error=None)

Message consumer.

auto_declare = True
callbacks = None

End all active queue consumers.

This does not affect already delivered messages, but it does mean the server will not send any more messages for this consumer.


Cancel consumer by queue name.

channel = None

End all active queue consumers.

This does not affect already delivered messages, but it does mean the server will not send any more messages for this consumer.


Declare queues, exchanges and bindings.

This is done automatically at instantiation if auto_declare is set.


Enable/disable flow from peer.

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.

The peer that receives a request to stop sending content will finish sending the current content (if any), and then wait until flow is reactivated.

no_ack = None
on_decode_error = None

Purge messages from all queues.


This will delete all ready messages, there is no undo operation.

qos(prefetch_size=0, prefetch_count=0, apply_global=False)

Specify quality of service.

The client can request that messages should 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.

The prefetch window is Ignored if the no_ack option is set.

  • prefetch_size – Specify the prefetch window 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 within other prefetch limits). May be set to zero, meaning “no specific limit”, although other prefetch limits may still apply.
  • prefetch_count – Specify the prefetch window in terms of whole messages.
  • apply_global – Apply new settings globally on all channels. Currently not supported by RabbitMQ.
queues = None
receive(body, message)

Method called when a message is received.

This dispatches to the registered callbacks.

  • body – The decoded message body.
  • message – The Message instance.
Raises NotImplementedError:

If no consumer callbacks have been registered.


Redeliver unacknowledged messages.

Asks the broker to redeliver all unacknowledged messages on the specified channel.

Parameters:requeue – By default the messages will be redelivered to the original recipient. With requeue set to true, the server will attempt to requeue the message, potentially then delivering it to an alternative subscriber.

Register a new callback to be called when a message is received.

The signature of the callback needs to accept two arguments: (body, message), which is the decoded message body and the Message instance (a subclass of Message.


Revive consumer after connection loss.

class AMQPBackend.Exchange(name='', type='', channel=None, **kwargs)

An Exchange declaration.


Name of the exchange. Default is no name (the default exchange).


AMQP defines four default exchange types (routing algorithms) that covers most of the common messaging use cases. An AMQP broker can also define additional exchange types, so see your broker manual for more information about available exchange types.

  • direct (default)

    Direct match between the routing key in the message, and the routing criteria used when a queue is bound to this exchange.

  • topic

    Wildcard match between the routing key and the routing pattern specified in the exchange/queue binding. The routing key is treated as zero or more words delimited by ”.” and supports special wildcard characters. “*” matches a single word and “#” matches zero or more words.

  • fanout

    Queues are bound to this exchange with no arguments. Hence any message sent to this exchange will be forwarded to all queues bound to this exchange.

  • headers

    Queues are bound to this exchange with a table of arguments containing headers and values (optional). A special argument named “x-match” determines the matching algorithm, where “all” implies an AND (all pairs must match) and “any” implies OR (at least one pair must match).

    arguments is used to specify the arguments.

This description of AMQP exchange types was shamelessly stolen from the blog post AMQP in 10 minutes: Part 4 by Rajith Attapattu. This article is recommended reading.


The channel the exchange is bound to (if bound).


Durable exchanges remain active when a server restarts. Non-durable exchanges (transient exchanges) are purged when a server restarts. Default is True.


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


The default delivery mode used for messages. The value is an integer, or alias string.

  • 1 or “transient”

    The message is transient. Which means it is stored in memory only, and is lost if the server dies or restarts.

  • 2 or “persistent” (default)

    The message is persistent. Which means the message is stored both in-memory, and on disk, and therefore preserved if the server dies or restarts.

The default value is 2 (persistent).


Additional arguments to specify when the exchange is declared.

Message(body, delivery_mode=None, priority=None, content_type=None, content_encoding=None, properties=None, headers=None)

Create message instance to be sent with publish().

  • body – Message body.
  • delivery_mode – Set custom delivery mode. Defaults to delivery_mode.
  • priority – Message priority, 0 to 9. (currently not supported by RabbitMQ).
  • content_type – The messages content_type. If content_type is set, no serialization occurs as it is assumed this is either a binary object, or you’ve done your own serialization. Leave blank if using built-in serialization as our library properly sets content_type.
  • content_encoding – The character set in which this object is encoded. Use “binary” if sending in raw binary objects. Leave blank if using built-in serialization as our library properly sets content_encoding.
  • properties – Message properties.
  • headers – Message headers.
attrs = (('name', None), ('type', None), ('arguments', None), ('durable', <type 'bool'>), ('auto_delete', <type 'bool'>), ('delivery_mode', <function <lambda> at 0x7fb4eb934a28>))
auto_delete = False

Declare the exchange.

Creates the exchange on the broker.

Parameters:nowait – If set the server will not respond, and a response will not be waited for. Default is False.
delete(if_unused=False, nowait=False)

Delete the exchange declaration on server.

  • if_unused – Delete only if the exchange has no bindings. Default is False.
  • nowait – If set the server will not respond, and a response will not be waited for. Default is False.
delivery_mode = 2
durable = True
name = ''
publish(message, routing_key=None, mandatory=False, immediate=False, exchange=None)

Publish message.

  • messageMessage() instance to publish.
  • routing_key – Routing key.
  • mandatory – Currently not supported.
  • immediate – Currently not supported.
type = 'direct'
class AMQPBackend.Producer(channel, exchange=None, routing_key=None, serializer=None, auto_declare=None, compression=None, on_return=None)

Message Producer.

  • channel – Connection or channel.
  • exchange – Optional default exchange.
  • routing_key – Optional default routing key.
  • serializer – Default serializer. Default is “json”.
  • compression – Default compression method. Default is no compression.
  • auto_declare – Automatically declare the default exchange at instantiation. Default is True.
  • on_return – Callback to call for undeliverable messages, when the mandatory or immediate arguments to publish() is used. This callback needs the following signature: (exception, exchange, routing_key, message). Note that the producer needs to drain events to use this feature.
auto_declare = True
channel = None
compression = None

Declare the exchange.

This happens automatically at instantiation if auto_declare is enabled.

exchange = None
maybe_declare(entity, retry=False, **retry_policy)

Declare the exchange if it hasn’t already been declared during this session.

on_return = None
publish(body, routing_key=None, delivery_mode=None, mandatory=False, immediate=False, priority=0, content_type=None, content_encoding=None, serializer=None, headers=None, compression=None, exchange=None, retry=False, retry_policy=None, declare=[], **properties)

Publish message to the specified exchange.

  • body – Message body.
  • routing_key – Message routing key.
  • delivery_mode – See delivery_mode.
  • mandatory – Currently not supported.
  • immediate – Currently not supported.
  • priority – Message priority. A number between 0 and 9.
  • content_type – Content type. Default is auto-detect.
  • content_encoding – Content encoding. Default is auto-detect.
  • serializer – Serializer to use. Default is auto-detect.
  • compression – Compression method to use. Default is none.
  • headers – Mapping of arbitrary headers to pass along with the message body.
  • exchange – Override the exchange. Note that this exchange must have been declared.
  • declare – Optional list of required entities that must have been declared before publishing the message. The entities will be declared using maybe_declare().
  • retry – Retry publishing, or declaring entities if the connection is lost.
  • retry_policy – Retry configuration, this is the keywords supported by ensure().
  • **properties – Additional message properties, see AMQP spec.

Revive the producer after connection loss.

routing_key = ''
serializer = None
class AMQPBackend.Queue(name='', exchange=None, routing_key='', channel=None, **kwargs)

A Queue declaration.


Name of the queue. Default is no name (default queue destination).


The Exchange the queue binds to.


The routing key (if any), also called binding key.

The interpretation of the routing key depends on the Exchange.type.

  • direct exchange

    Matches if the routing key property of the message and the routing_key attribute are identical.

  • fanout exchange

    Always matches, even if the binding does not have a key.

  • topic exchange

    Matches the routing key property of the message by a primitive pattern matching scheme. The message routing key then consists of words separated by dots (”.”, like domain names), and two special characters are available; star (“*”) and hash (“#”). The star matches any word, and the hash matches zero or more words. For example “*.stock.#” matches the routing keys “usd.stock” and “eur.stock.db” but not “stock.nasdaq”.


The channel the Queue is bound to (if bound).


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.

Default is True.


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

Default is False.


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.


Additional arguments used when declaring the queue.


Additional arguments used when binding the queue.


Unused in Kombu, but applications can take advantage of this. For example to give alternate names to queues with automatically generated queue names.

attrs = (('name', None), ('exchange', None), ('routing_key', None), ('queue_arguments', None), ('binding_arguments', None), ('durable', <type 'bool'>), ('exclusive', <type 'bool'>), ('auto_delete', <type 'bool'>), ('no_ack', None), ('alias', None))
auto_delete = False

Cancel a consumer by consumer tag.

consume(consumer_tag='', callback=None, no_ack=None, nowait=False)

Start a queue consumer.

Consumers last as long as the channel they were created on, or until the client cancels them.

  • consumer_tag – Unique 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.
  • no_ack – If set messages received does not have to be acknowledged.
  • nowait – Do not wait for a reply.
  • callback – callback called for each delivered message

Declares the queue, the exchange and binds the queue to the exchange.

delete(if_unused=False, if_empty=False, nowait=False)

Delete the queue.

  • if_unused – If set, the server will only delete the queue if it has no consumers. A channel error will be raised if the queue has consumers.
  • if_empty – If set, the server will only delete the queue if it is empty. If it is not empty a channel error will be raised.
  • nowait – Do not wait for a reply.
durable = True
exchange = <unbound Exchange (direct)>
exclusive = False

Poll the server for a new message.

Returns the message instance if a message was available, or None otherwise.

Parameters:no_ack – If set messages received does not have to be acknowledged.

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

name = ''
no_ack = False

Remove all ready messages from the queue.


Create the queue binding on the server.

queue_declare(nowait=False, passive=False)

Declare queue on the server.

  • nowait – Do not wait for a reply.
  • passive – 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.
routing_key = ''

Delete the binding on the server.

AMQPBackend.consume(task_id, timeout=None)
AMQPBackend.drain_events(connection, consumer, timeout=None, now=<built-in function time>)
AMQPBackend.get_many(task_ids, timeout=None, **kwargs)
AMQPBackend.get_task_meta(task_id, cache=True)
AMQPBackend.poll(task_id, backlog_limit=100)

Reload taskset result, even if it has been previously fetched.

AMQPBackend.restore_taskset(taskset_id, cache=True)
AMQPBackend.save_taskset(taskset_id, result)
AMQPBackend.wait_for(task_id, timeout=None, cache=True, propagate=True, **kwargs)
exception celery.backends.amqp.BacklogLimitExceeded

Too much state history to fast-forward.