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

Carrot Compatibility - kombu.compat

Carrot compatibility interface.

See https://pypi.org/project/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]

Carrot compatible producer.

auto_declare = True

By default, if a defualt exchange is set, that exchange will be declare when publishing a message.

auto_delete = False
property backend
property channel
close()[source]
compression = None

Default compression method. Disabled by default.

property connection
declare()

Declare the exchange.

Note

This happens automatically at instantiation when the auto_declare flag is enabled.

durable = True
exchange = ''

Default exchange

exchange_type = 'direct'
maybe_declare(entity, retry=False, **retry_policy)

Declare exchange if not already declared during this session.

on_return = None

Basic return callback.

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=None, expiration=None, timeout=None, **properties)

Publish message to the specified exchange.

Parameters
  • body (Any) – Message body.

  • routing_key (str) – Message routing key.

  • delivery_mode (enum) – See delivery_mode.

  • mandatory (bool) – Currently not supported.

  • immediate (bool) – Currently not supported.

  • priority (int) – Message priority. A number between 0 and 9.

  • content_type (str) – Content type. Default is auto-detect.

  • content_encoding (str) – Content encoding. Default is auto-detect.

  • serializer (str) – Serializer to use. Default is auto-detect.

  • compression (str) – Compression method to use. Default is none.

  • headers (Dict) – Mapping of arbitrary headers to pass along with the message body.

  • exchange (kombu.entity.Exchange, str) – Override the exchange. Note that this exchange must have been declared.

  • declare (Sequence[EntityT]) – Optional list of required entities that must have been declared before publishing the message. The entities will be declared using maybe_declare().

  • retry (bool) – Retry publishing, or declaring entities if the connection is lost.

  • retry_policy (Dict) – Retry configuration, this is the keywords supported by ensure().

  • expiration (float) – A TTL in seconds can be specified per message. Default is no expiration.

  • timeout (float) – Set timeout to wait maximum timeout second for message to publish.

  • **properties (Any) – Additional message properties, see AMQP spec.

release()
revive(channel)

Revive the producer after connection loss.

routing_key = ''

Default routing key.

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

Default serializer to use. Default is JSON.

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]

Carrot compatible consumer.

exception ContentDisallowed

Consumer does not allow this content-type.

args
with_traceback()

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

accept = None

List of accepted content-types.

An exception will be raised if the consumer receives a message with an untrusted content type. By default all content-types are accepted, but not if kombu.disable_untrusted_serializers() was called, in which case only json is allowed.

add_queue(queue)[source]

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

Note

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

auto_declare = True

By default all entities will be declared at instantiation, if you want to handle this manually you can set this to False.

auto_delete = False
callbacks = None

List of callbacks called in order when a message is received.

The signature of the callbacks must take two arguments: (body, message), which is the decoded message body and the Message instance.

cancel()[source]

End all active queue consumers.

Note

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

cancel_by_queue(queue)[source]

Cancel consumer by queue name.

channel = None

The connection/channel to use for this consumer.

close()[source]

End all active queue consumers.

Note

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

property connection
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 (bool) – See no_ack.

consuming_from(queue)[source]

Return True if currently consuming from queue’.

declare()[source]

Declare queues, exchanges and bindings.

Note

This is done automatically at instantiation when auto_declare is set.

discard_all(filterfunc=None)[source]
durable = True
exchange = ''
exchange_type = 'direct'
exclusive = False
fetch(no_ack=None, enable_callbacks=False)[source]
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.

iterconsume(limit=None, no_ack=None)[source]
iterqueue(limit=None, infinite=False)[source]
no_ack = None

Flag for automatic message acknowledgment. If enabled the messages are automatically acknowledged by the broker. This can increase performance but means that you have no control of when the message is removed.

Disabled by default.

on_decode_error = None

Callback called when a message can’t be decoded.

The signature of the callback must take two arguments: (message, exc), which is the message that can’t be decoded and the exception that occurred while trying to decode it.

on_message = None

Optional function called whenever a message is received.

When defined this function will be called instead of the receive() method, and callbacks will be disabled.

So this can be used as an alternative to callbacks when you don’t want the body to be automatically decoded. Note that the message will still be decompressed if the message has the compression header set.

The signature of the callback must take a single argument, which is the Message object.

Also note that the message.body attribute, which is the raw contents of the message body, may in some cases be a read-only buffer object.

prefetch_count = None

Initial prefetch count

If set, the consumer will set the prefetch_count QoS value at startup. Can also be changed using qos().

process_next()[source]
purge()[source]

Purge messages from all queues.

Warning

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

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 (int) – 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 (int) – Specify the prefetch window in terms of whole messages.

  • apply_global (bool) – Apply new settings globally on all channels.

queue = ''
property queues
receive(body, message)[source]

Method called when a message is received.

This dispatches to the registered callbacks.

Parameters
  • body (Any) – The decoded message body.

  • message (Message) – The message instance.

Raises

NotImplementedError – If no consumer callbacks have been registered.

recover(requeue=False)[source]

Redeliver unacknowledged messages.

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

Parameters

requeue (bool) – 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_callback(callback)[source]

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

Note

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

revive(channel)[source]

Revive consumer after connection loss.

routing_key = ''
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
with_traceback()

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

accept = None

List of accepted content-types.

An exception will be raised if the consumer receives a message with an untrusted content type. By default all content-types are accepted, but not if kombu.disable_untrusted_serializers() was called, in which case only json is allowed.

add_consumer(consumer)[source]
add_consumer_from_dict(queue, **options)[source]
add_queue(queue)

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

Note

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

auto_declare = True

By default all entities will be declared at instantiation, if you want to handle this manually you can set this to False.

callbacks = None

List of callbacks called in order when a message is received.

The signature of the callbacks must take two arguments: (body, message), which is the decoded message body and the Message instance.

cancel()

End all active queue consumers.

Note

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

cancel_by_queue(queue)

Cancel consumer by queue name.

channel = None

The connection/channel to use for this consumer.

close()[source]

End all active queue consumers.

Note

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

property connection
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 (bool) – See no_ack.

consuming_from(queue)

Return True if currently consuming from queue’.

declare()

Declare queues, exchanges and bindings.

Note

This is done automatically at instantiation when auto_declare is set.

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

iterconsume(limit=None, no_ack=False)[source]
no_ack = None

Flag for automatic message acknowledgment. If enabled the messages are automatically acknowledged by the broker. This can increase performance but means that you have no control of when the message is removed.

Disabled by default.

on_decode_error = None

Callback called when a message can’t be decoded.

The signature of the callback must take two arguments: (message, exc), which is the message that can’t be decoded and the exception that occurred while trying to decode it.

on_message = None

Optional function called whenever a message is received.

When defined this function will be called instead of the receive() method, and callbacks will be disabled.

So this can be used as an alternative to callbacks when you don’t want the body to be automatically decoded. Note that the message will still be decompressed if the message has the compression header set.

The signature of the callback must take a single argument, which is the Message object.

Also note that the message.body attribute, which is the raw contents of the message body, may in some cases be a read-only buffer object.

prefetch_count = None

Initial prefetch count

If set, the consumer will set the prefetch_count QoS value at startup. Can also be changed using qos().

purge()

Purge messages from all queues.

Warning

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.

Parameters
  • prefetch_size (int) – 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 (int) – Specify the prefetch window in terms of whole messages.

  • apply_global (bool) – Apply new settings globally on all channels.

property queues
receive(body, message)

Method called when a message is received.

This dispatches to the registered callbacks.

Parameters
  • body (Any) – The decoded message body.

  • message (Message) – The message instance.

Raises

NotImplementedError – If no consumer callbacks have been registered.

recover(requeue=False)

Redeliver unacknowledged messages.

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

Parameters

requeue (bool) – 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_callback(callback)

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

Note

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

revive(channel)[source]

Revive consumer after connection loss.