2010-12-01 11:28:31 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
Example that sends a single message and exits using the simple interface.
|
|
|
|
|
|
|
|
You can use `simple_receive.py` (or `complete_receive.py`) to receive the
|
|
|
|
message sent.
|
|
|
|
|
|
|
|
"""
|
2016-04-06 20:14:05 +00:00
|
|
|
|
2010-12-01 11:28:31 +00:00
|
|
|
import eventlet
|
|
|
|
|
2012-06-24 15:32:17 +00:00
|
|
|
from kombu import Connection
|
2010-12-01 11:28:31 +00:00
|
|
|
|
|
|
|
eventlet.monkey_patch()
|
|
|
|
|
|
|
|
|
|
|
|
def wait_many(timeout=1):
|
|
|
|
|
|
|
|
#: 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 connection:
|
|
|
|
|
|
|
|
#: 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 connection.SimpleQueue('kombu_demo') as queue:
|
|
|
|
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
message = queue.get(block=False, timeout=timeout)
|
2013-09-10 16:26:12 +00:00
|
|
|
except queue.Empty:
|
2012-06-24 15:32:17 +00:00
|
|
|
break
|
|
|
|
else:
|
|
|
|
message.ack()
|
|
|
|
print(message.payload)
|
2010-12-01 11:28:31 +00:00
|
|
|
|
2021-07-20 13:07:49 +00:00
|
|
|
|
2012-09-21 13:18:16 +00:00
|
|
|
eventlet.spawn(wait_many).wait()
|