Producers

Basics

Serialization

See Serialization.

Reference

class kombu.messaging.Producer(channel, exchange=None, routing_key=None, serializer=None, auto_declare=None, compression=None, on_return=None)

Message Producer.

Parameters:
  • 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.
Producer.auto_declare = True

By default the exchange is declared at instantiation. If you want to declare manually then you can set this to False.

Producer.channel = None

The connection channel used.

Producer.compression = None

Default compression method. Disabled by default.

Producer.declare()

Declare the exchange.

This happens automatically at instantiation if auto_declare is enabled.

Producer.exchange = None

Default exchange.

Producer.maybe_declare(entity, retry=False, **retry_policy)

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

Producer.on_return = None

Basic return callback.

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

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().
  • **properties – Additional message properties, see AMQP spec.
Producer.revive(channel)

Revive the producer after connection loss.

Producer.serializer = None

Default serializer to use. Default is JSON.

Table Of Contents

Previous topic

Connections and transports

Next topic

Consumers

This Page