你正在阅读 Celery 3.1 的文档。开发版本文档见: 此处.

celery.backends.amqp

celery.backends.amqp

The AMQP result backend.

This backend publishes results as messages.

exception celery.backends.amqp.BacklogLimitExceeded[源代码]

Too much state history to fast-forward.

class celery.backends.amqp.AMQPBackend(app, 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, on_message=None, accept=None)

Message consumer.

参数:
exception ContentDisallowed

Consumer does not allow this content-type.

AMQPBackend.Consumer.accept = None
AMQPBackend.Consumer.add_queue(queue)

Add a queue to the list of queues to consume from.

This will not start consuming from the queue, for that you will have to call consume() after.

AMQPBackend.Consumer.add_queue_from_dict(queue, **options)

This method is deprecated.

Instead please use:

consumer.add_queue(Queue.from_dict(d))
AMQPBackend.Consumer.auto_declare = True
AMQPBackend.Consumer.callbacks = None
AMQPBackend.Consumer.cancel()

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.

AMQPBackend.Consumer.cancel_by_queue(queue)

Cancel consumer by queue name.

AMQPBackend.Consumer.channel = None
AMQPBackend.Consumer.close()

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.

AMQPBackend.Consumer.connection None
AMQPBackend.Consumer.consume(no_ack=None)

Start consuming messages.

Can be called multiple times, but note that while it will consume from new queues added since the last call, it will not cancel consuming from removed queues ( use cancel_by_queue()).

参数:no_ack – See no_ack.
AMQPBackend.Consumer.consuming_from(queue)

Return True if the consumer is currently consuming from queue’.

AMQPBackend.Consumer.declare()

Declare queues, exchanges and bindings.

This is done automatically at instantiation if auto_declare is set.

AMQPBackend.Consumer.flow(active)

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.

AMQPBackend.Consumer.no_ack = None
AMQPBackend.Consumer.on_decode_error = None
AMQPBackend.Consumer.on_message = None
AMQPBackend.Consumer.purge()

Purge messages from all queues.

警告

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

AMQPBackend.Consumer.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.
AMQPBackend.Consumer.queues = None
AMQPBackend.Consumer.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.
引发 NotImplementedError:
 

If no consumer callbacks have been registered.

AMQPBackend.Consumer.recover(requeue=False)

Redeliver unacknowledged messages.

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

参数: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.
AMQPBackend.Consumer.register_callback(callback)

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.

AMQPBackend.Consumer.revive(channel)

Revive consumer after connection loss.

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

An Exchange declaration.

参数:
name

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

type

This description of AMQP exchange types was shamelessly stolen from the blog post `AMQP in 10 minutes: Part 4`_ by Rajith Attapattu. Reading this article is recommended if you’re new to amqp.

“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.

channel

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

durable

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

auto_delete

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

delivery_mode

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

arguments

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.
PERSISTENT_DELIVERY_MODE = 2
TRANSIENT_DELIVERY_MODE = 1
attrs = (('name', None), ('type', None), ('arguments', None), ('durable', <type 'bool'>), ('passive', <type 'bool'>), ('auto_delete', <type 'bool'>), ('delivery_mode', <function <lambda> at 0xae8ee9c>))
auto_delete = False
bind_to(exchange='', routing_key='', arguments=None, nowait=False, **kwargs)

Binds the exchange to another exchange.

参数:nowait – If set the server will not respond, and the call will not block waiting for a response. Default is False.
binding(routing_key='', arguments=None, unbind_arguments=None)
can_cache_declaration None
declare(nowait=False, passive=None)

Declare the exchange.

Creates the exchange on the broker.

参数: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 = ''
passive = False
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'
unbind_from(source='', routing_key='', nowait=False, arguments=None)

Delete previously created exchange binding from the server.

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
close()
compression = None
connection None
declare()

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.
release()
revive(channel)

Revive the producer after connection loss.

routing_key = ''
serializer = None
AMQPBackend.Queue

NoCacheQueue 的别名

AMQPBackend.consume(task_id, timeout=None)[源代码]
AMQPBackend.delete_group(group_id)[源代码]
AMQPBackend.destination_for(task_id, request)
AMQPBackend.drain_events(connection, consumer, timeout=None, now=<function _monotonic at 0x93ee4c4>, wait=None)[源代码]
AMQPBackend.get_many(task_ids, timeout=None, now=<function _monotonic at 0x93ee4c4>, getfields=<operator.itemgetter object at 0xa8f7e4c>, READY_STATES=frozenset(['FAILURE', 'REVOKED', 'SUCCESS']), PROPAGATE_STATES=frozenset(['FAILURE', 'REVOKED']), **kwargs)[源代码]
AMQPBackend.get_task_meta(task_id, backlog_limit=1000)[源代码]
AMQPBackend.on_reply_declare(task_id)
AMQPBackend.persistent = True
AMQPBackend.poll(task_id, backlog_limit=1000)
AMQPBackend.reload_group_result(task_id)[源代码]

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

AMQPBackend.reload_task_result(task_id)[源代码]
AMQPBackend.restore_group(group_id, cache=True)[源代码]
AMQPBackend.retry_policy = {'interval_start': 0, 'interval_max': 1, 'max_retries': 20, 'interval_step': 1}
AMQPBackend.revive(channel)[源代码]
AMQPBackend.rkey(task_id)
AMQPBackend.save_group(group_id, result)[源代码]
AMQPBackend.store_result(task_id, result, status, traceback=None, request=None, **kwargs)

Send task return value and status.

AMQPBackend.supports_autoexpire = True
AMQPBackend.supports_native_join = True
AMQPBackend.wait_for(task_id, timeout=None, cache=True, propagate=True, READY_STATES=frozenset(['FAILURE', 'REVOKED', 'SUCCESS']), PROPAGATE_STATES=frozenset(['FAILURE', 'REVOKED']), **kwargs)[源代码]

上一个主题

celery.backends.cache

下一个主题

celery.backends.mongodb

本页