kombu/examples/memory_transport.py

25 lines
700 B
Python
Raw Normal View History

2016-09-24 17:45:49 +00:00
"""
Example that use memory transport for message produce.
"""
import time
from kombu import Connection, Exchange, Queue, Consumer
media_exchange = Exchange('media', 'direct')
video_queue = Queue('video', exchange=media_exchange, routing_key='video')
task_queues = [video_queue]
def handle_message(body, message):
2020-07-13 13:58:06 +00:00
print(f"{time.time()} RECEIVED MESSAGE: {body!r}")
2016-09-24 17:45:49 +00:00
message.ack()
connection = Connection("memory:///")
consumer = Consumer(connection, task_queues, callbacks=[handle_message])
producer = connection.Producer(serializer='json')
producer.publish({"foo": "bar"}, exchange=media_exchange, routing_key='video', declare=task_queues)
consumer.consume()
connection.drain_events()