2010-12-01 11:28:10 +00:00
|
|
|
"""
|
|
|
|
Example receiving a message using the SimpleQueue interface.
|
2016-04-06 20:14:05 +00:00
|
|
|
|
2010-12-01 11:28:10 +00:00
|
|
|
"""
|
2012-11-13 13:44:41 +00:00
|
|
|
|
2022-04-14 11:02:52 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2012-06-24 15:32:17 +00:00
|
|
|
from kombu import Connection
|
2010-12-01 11:28:10 +00:00
|
|
|
|
|
|
|
#: 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.
|
2012-06-24 15:32:17 +00:00
|
|
|
with Connection('amqp://guest:guest@localhost:5672//') as conn:
|
2010-12-01 11:28:10 +00:00
|
|
|
|
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.
|
2012-06-24 15:32:17 +00:00
|
|
|
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-04-05 11:03:14 +00:00
|
|
|
|
2011-09-07 14:21:38 +00:00
|
|
|
####
|
2024-09-25 19:34:56 +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()
|