kombu.compat

Carrot compatible interface for Publisher and Producer.

See http://packages.python.org/pypi/carrot for documentation.

Publisher

Replace with kombu.Producer.

class kombu.compat.Publisher(connection, exchange=None, routing_key=None, exchange_type=None, durable=None, auto_delete=None, channel=None, **kwargs)[source]
auto_declare = True
auto_delete = False
backend
channel
close()[source]
compression = None
connection
declare()

Declare the exchange.

This happens automatically at instantiation if auto_declare is enabled.

durable = True
exchange = ''
exchange_type = 'direct'
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=[], expiration=None, **properties)

Publish message to the specified exchange.

Parameters:
  • 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().
  • expiration – A TTL in seconds can be specified per message. Default is no expiration.
  • **properties – Additional message properties, see AMQP spec.
release()
revive(channel)

Revive the producer after connection loss.

routing_key = ''
send(*args, **kwargs)[source]
serializer = None

Consumer

Replace with kombu.Consumer.

class kombu.compat.Consumer(connection, queue=None, exchange=None, routing_key=None, exchange_type=None, durable=None, exclusive=None, auto_delete=None, **kwargs)[source]
exception ContentDisallowed

Consumer does not allow this content-type.

args
message
Consumer.accept = None
Consumer.add_queue(queue)[source]

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.

Consumer.add_queue_from_dict(queue, **options)[source]

This method is deprecated.

Instead please use:

consumer.add_queue(Queue.from_dict(d))
Consumer.auto_declare = True
Consumer.auto_delete = False
Consumer.callbacks = None
Consumer.cancel()[source]

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.

Consumer.cancel_by_queue(queue)[source]

Cancel consumer by queue name.

Consumer.channel = None
Consumer.close()[source]
Consumer.connection
Consumer.consume(no_ack=None)[source]

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

Parameters:no_ack – See no_ack.
Consumer.consuming_from(queue)[source]

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

Consumer.declare()[source]

Declare queues, exchanges and bindings.

This is done automatically at instantiation if auto_declare is set.

Consumer.discard_all(filterfunc=None)[source]
Consumer.durable = True
Consumer.exchange = ''
Consumer.exchange_type = 'direct'
Consumer.exclusive = False
Consumer.fetch(no_ack=None, enable_callbacks=False)[source]
Consumer.flow(active)[source]

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.

Consumer.iterconsume(limit=None, no_ack=None)[source]
Consumer.iterqueue(limit=None, infinite=False)[source]
Consumer.no_ack = None
Consumer.on_decode_error = None
Consumer.on_message = None
Consumer.process_next()[source]
Consumer.purge()[source]

Purge messages from all queues.

Warning

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

Consumer.qos(prefetch_size=0, prefetch_count=0, apply_global=False)[source]

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.

Parameters:
  • 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.
Consumer.queue = ''
Consumer.queues = None
Consumer.receive(body, message)[source]

Method called when a message is received.

This dispatches to the registered callbacks.

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

NotImplementedError – If no consumer callbacks have been registered.

Consumer.recover(requeue=False)[source]

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.
Consumer.register_callback(callback)[source]

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.

Consumer.revive(channel)[source]
Consumer.routing_key = ''
Consumer.wait(limit=None)[source]

ConsumerSet

Replace with kombu.Consumer.

class kombu.compat.ConsumerSet(connection, from_dict=None, consumers=None, channel=None, **kwargs)[source]
exception ContentDisallowed

Consumer does not allow this content-type.

args
message
ConsumerSet.accept = None
ConsumerSet.add_consumer(consumer)[source]
ConsumerSet.add_consumer_from_dict(queue, **options)[source]
ConsumerSet.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.

ConsumerSet.add_queue_from_dict(queue, **options)

This method is deprecated.

Instead please use:

consumer.add_queue(Queue.from_dict(d))
ConsumerSet.auto_declare = True
ConsumerSet.callbacks = None
ConsumerSet.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.

ConsumerSet.cancel_by_queue(queue)

Cancel consumer by queue name.

ConsumerSet.channel = None
ConsumerSet.close()[source]
ConsumerSet.connection
ConsumerSet.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()).

Parameters:no_ack – See no_ack.
ConsumerSet.consuming_from(queue)

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

ConsumerSet.declare()

Declare queues, exchanges and bindings.

This is done automatically at instantiation if auto_declare is set.

ConsumerSet.discard_all()[source]
ConsumerSet.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.

ConsumerSet.iterconsume(limit=None, no_ack=False)[source]
ConsumerSet.no_ack = None
ConsumerSet.on_decode_error = None
ConsumerSet.on_message = None
ConsumerSet.purge()

Purge messages from all queues.

Warning

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

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

Parameters:
  • 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.
ConsumerSet.queues = None
ConsumerSet.receive(body, message)

Method called when a message is received.

This dispatches to the registered callbacks.

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

NotImplementedError – If no consumer callbacks have been registered.

ConsumerSet.recover(requeue=False)

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

ConsumerSet.revive(channel)[source]