2010-11-24 11:31:20 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
Example producer that sends a single message and exits.
|
|
|
|
|
2010-12-02 14:24:35 +00:00
|
|
|
You can use `complete_receive.py` to receive the message sent.
|
2010-11-24 11:31:20 +00:00
|
|
|
|
|
|
|
"""
|
2016-04-06 20:14:05 +00:00
|
|
|
|
2021-07-20 13:07:49 +00:00
|
|
|
from kombu import Connection, Exchange, Producer, Queue
|
2010-11-24 11:31:20 +00:00
|
|
|
|
|
|
|
#: By default messages sent to exchanges are persistent (delivery_mode=2),
|
|
|
|
#: and queues and exchanges are durable.
|
2012-09-20 18:46:04 +00:00
|
|
|
exchange = Exchange('kombu_demo', type='direct')
|
|
|
|
queue = Queue('kombu_demo', exchange, routing_key='kombu_demo')
|
|
|
|
|
|
|
|
|
|
|
|
with Connection('amqp://guest:guest@localhost:5672//') as connection:
|
2011-09-07 14:21:38 +00:00
|
|
|
|
|
|
|
#: Producers are used to publish messages.
|
2016-08-01 20:45:21 +00:00
|
|
|
#: a default exchange and routing key can also be specified
|
2011-09-07 14:21:38 +00:00
|
|
|
#: as arguments the Producer, but we rather specify this explicitly
|
|
|
|
#: at the publish call.
|
2012-06-24 15:32:17 +00:00
|
|
|
producer = Producer(connection)
|
2011-09-07 14:21:38 +00:00
|
|
|
|
|
|
|
#: Publish the message using the json serializer (which is the default),
|
|
|
|
#: and zlib compression. The kombu consumer will automatically detect
|
2012-06-24 15:32:17 +00:00
|
|
|
#: encoding, serialization and compression used and decode accordingly.
|
2021-07-20 13:07:49 +00:00
|
|
|
producer.publish(
|
|
|
|
{'hello': 'world'},
|
|
|
|
exchange=exchange,
|
|
|
|
routing_key='kombu_demo',
|
|
|
|
serializer='json',
|
|
|
|
compression='zlib',
|
|
|
|
)
|