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
|
|
|
|
2022-04-14 11:02:52 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
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()
|
|
|
|
|
2011-04-21 16:29:51 +00:00
|
|
|
|
2010-12-01 11:28:31 +00:00
|
|
|
def send_many(n):
|
|
|
|
|
|
|
|
#: 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:
|
2010-12-01 11:28:31 +00:00
|
|
|
|
2012-06-24 15:32:17 +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 connection.SimpleQueue('kombu_demo') as queue:
|
2010-12-01 11:28:31 +00:00
|
|
|
|
2012-06-24 15:32:17 +00:00
|
|
|
def send_message(i):
|
2020-07-13 13:58:06 +00:00
|
|
|
queue.put({'hello': f'world{i}'})
|
2010-12-01 11:28:31 +00:00
|
|
|
|
2012-06-24 15:32:17 +00:00
|
|
|
pool = eventlet.GreenPool(10)
|
2013-09-10 16:26:12 +00:00
|
|
|
for i in range(n):
|
2012-06-24 15:32:17 +00:00
|
|
|
pool.spawn(send_message, i)
|
|
|
|
pool.waitall()
|
2010-12-01 11:28:31 +00:00
|
|
|
|
2011-09-07 14:21:38 +00:00
|
|
|
|
2012-06-24 15:32:17 +00:00
|
|
|
if __name__ == '__main__':
|
2010-12-01 11:28:31 +00:00
|
|
|
send_many(10)
|