From cb6647e516f4c7246e04e19d9fef15d3d4e8ef93 Mon Sep 17 00:00:00 2001 From: kindule Date: Sun, 25 Sep 2016 01:45:49 +0800 Subject: [PATCH] memory transport example (#627) --- examples/memory_transport.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 examples/memory_transport.py diff --git a/examples/memory_transport.py b/examples/memory_transport.py new file mode 100644 index 00000000..f0b43940 --- /dev/null +++ b/examples/memory_transport.py @@ -0,0 +1,24 @@ +""" +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): + print("%s RECEIVED MESSAGE: %r" % (time.time(), body)) + 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()