File: simple_receive.py

package info (click to toggle)
kombu 5.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,968 kB
  • sloc: python: 28,815; makefile: 318
file content (29 lines) | stat: -rw-r--r-- 939 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
"""
Example receiving a message using the SimpleQueue interface.

"""

from __future__ import annotations

from kombu import Connection

#: Create connection
#: If hostname, userid, password and virtual_host is not specified
#: the values below are the default, but listed here so it can
#: be easily changed.
with Connection('amqp://guest:guest@localhost:5672//') as conn:

    #: SimpleQueue mimics the interface of the Python Queue module.
    #: First argument can either be a queue name or a kombu.Queue object.
    #: If a name, then the queue will be declared with the name as the queue
    #: name, exchange name and routing key.
    with conn.SimpleQueue('kombu_demo') as queue:
        message = queue.get(block=True, timeout=10)
        message.ack()
        print(message.payload)

####
#: If you don't use the with statement then you must always
# remember to close objects after use:
#   queue.close()
#   connection.close()