kombu/examples/simple_receive.py

30 lines
939 B
Python
Raw Permalink Normal View History

"""
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:
2011-09-07 14:21:38 +00:00
#: 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:
2011-09-07 14:21:38 +00:00
message = queue.get(block=True, timeout=10)
message.ack()
print(message.payload)
2011-09-07 14:21:38 +00:00
####
#: If you don't use the with statement then you must always
2011-09-07 14:21:38 +00:00
# remember to close objects after use:
# queue.close()
# connection.close()