From 6f09910527bd69b0a52d53686084fccd8ba97018 Mon Sep 17 00:00:00 2001 From: Rumyana Neykova Date: Thu, 23 Aug 2012 10:58:39 +0100 Subject: [PATCH] Modify complete_send/receive examples to use exchange to exchange binding --- examples/complete_receive.py | 22 ++++++++++++++++------ examples/complete_send.py | 11 +++++------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/examples/complete_receive.py b/examples/complete_receive.py index aa3987bf..e0093c0b 100644 --- a/examples/complete_receive.py +++ b/examples/complete_receive.py @@ -10,8 +10,6 @@ from pprint import pformat #: By default messages sent to exchanges are persistent (delivery_mode=2), #: and queues and exchanges are durable. -exchange = Exchange('kombu_demo', type='direct') -queue = Queue('kombu_demo', exchange, routing_key='kombu_demo') def pretty(obj): @@ -29,8 +27,18 @@ def handle_message(body, message): #: 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: - +with Connection('pyamqp://guest:guest@localhost:5672//') as connection: + + """The configuration of the message flow is as follows: + gateway_kombu_exchange -> internal_kombu_exchange -> kombu_demo queue + """ + gateway_exchange = Exchange('gateway_kombu_demo', type='direct') + exchange = Exchange('internal_kombu_demo', type='direct') + binded = exchange.bind(connection.channel()) + binded.exchange_bind(gateway_exchange, routing_key = 'kombu_demo') + + queue = Queue('kombu_demo', exchange, routing_key='kombu_demo') + #: Create consumer using our callback and queue. #: Second argument can also be a list to consume from #: any number of queues. @@ -38,5 +46,7 @@ with Connection('amqp://guest:guest@localhost:5672//') as connection: #: This waits for a single event. Note that this event may not #: be a message, or a message that is to be delivered to the consumers - #: channel, but any event received on the connection. - eventloop(connection, limit=1, timeout=10.0) + #: channel, but any event received on the connection. + recv = eventloop(connection) + while True: + recv.next() diff --git a/examples/complete_send.py b/examples/complete_send.py index c81f8620..83de890b 100644 --- a/examples/complete_send.py +++ b/examples/complete_send.py @@ -11,12 +11,11 @@ from kombu import Connection, Producer, Exchange, Queue #: By default messages sent to exchanges are persistent (delivery_mode=2), #: and queues and exchanges are durable. -exchange = Exchange('kombu_demo', type='direct') -queue = Queue('kombu_demo', exchange, routing_key='kombu_demo') - - -with Connection('amqp://guest:guest@localhost:5672//') as connection: +gateway_exchange = Exchange('gateway_kombu_demo', type='direct') +with Connection('pyamqp://guest:guest@localhost:5672//') as connection: + #binded = exchange.bind(connection.channel()) + #binded.exchange_bind(gateway_exchange, routing_key = 'kombu_demo') #: Producers are used to publish messages. #: a default exchange and routing key can also be specifed #: as arguments the Producer, but we rather specify this explicitly @@ -27,6 +26,6 @@ with Connection('amqp://guest:guest@localhost:5672//') as connection: #: and zlib compression. The kombu consumer will automatically detect #: encoding, serialization and compression used and decode accordingly. producer.publish({'hello': 'world'}, - exchange=exchange, + exchange=gateway_exchange, routing_key='kombu_demo', serializer='json', compression='zlib')