Producers¶
Basics¶
Serialization¶
See Serialization.
Reference¶
-
class
kombu.
Producer
(channel, exchange=None, routing_key=None, serializer=None, auto_declare=None, compression=None, on_return=None)[source] 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.
-
auto_declare
= True By default the exchange is declared at instantiation. If you want to declare manually then you can set this to
False
.
-
compression
= None Default compression method. Disabled by default.
-
declare
()[source] Declare the exchange.
This happens automatically at instantiation if
auto_declare
is enabled.
-
exchange
= None Default exchange
-
maybe_declare
(entity, retry=False, **retry_policy)[source] Declare the exchange if it hasn’t already been 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=[], expiration=None, **properties)[source] 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.
-
revive
(channel)[source] Revive the producer after connection loss.
-
routing_key
= '' Default routing key.
-
serializer
= None Default serializer to use. Default is JSON.