forked from celery/kombu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_eventlet_receive.py
43 lines (29 loc) · 1.2 KB
/
simple_eventlet_receive.py
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
37
38
39
40
41
42
43
"""
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.
"""
from __future__ import annotations
import eventlet
from kombu import Connection
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.
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)
except queue.Empty:
break
else:
message.ack()
print(message.payload)
eventlet.spawn(wait_many).wait()