File: complete_send.py

package info (click to toggle)
kombu 5.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,972 kB
  • sloc: python: 28,634; makefile: 318; sh: 8
file content (36 lines) | stat: -rw-r--r-- 1,174 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""

Example producer that sends a single message and exits.

You can use `complete_receive.py` to receive the message sent.

"""

from __future__ import annotations

from kombu import Connection, Exchange, Producer, Queue

#: By default messages sent to exchanges are persistent (delivery_mode=2),
#: and queues and exchanges are durable.
exchange = Exchange('kombu_demo', type='direct')
queue = Queue('kombu_demo', exchange, routing_key='kombu_demo')


with Connection('amqp://guest:guest@localhost:5672//') as connection:

    #: Producers are used to publish messages.
    #: a default exchange and routing key can also be specified
    #: as arguments the Producer, but we rather specify this explicitly
    #: at the publish call.
    producer = Producer(connection)

    #: Publish the message using the json serializer (which is the default),
    #: and zlib compression.  The kombu consumer will automatically detect
    #: encoding, serialization and compression used and decode accordingly.
    producer.publish(
        {'hello': 'world'},
        exchange=exchange,
        routing_key='kombu_demo',
        serializer='json',
        compression='zlib',
    )