diff options
Diffstat (limited to 'python/examples/pubsub')
-rw-r--r-- | python/examples/pubsub/topic_publisher.py (renamed from python/examples/pubsub/topic_producer.py) | 26 | ||||
-rw-r--r-- | python/examples/pubsub/topic_subscriber.py (renamed from python/examples/pubsub/topic_consumer.py) | 14 |
2 files changed, 15 insertions, 25 deletions
diff --git a/python/examples/pubsub/topic_producer.py b/python/examples/pubsub/topic_publisher.py index c3b13cd82c..1ff983b315 100644 --- a/python/examples/pubsub/topic_producer.py +++ b/python/examples/pubsub/topic_publisher.py @@ -1,6 +1,6 @@ #!/usr/bin/env python """ - topic_producer.py + topic_publisher.py This is a simple AMQP publisher application that uses a Topic exchange. The publisher specifies the routing key @@ -37,10 +37,6 @@ session.session_open() # topic exchange. The routing keys are "usa.news", "usa.weather", # "europe.news", and "europe.weather". -final = "That's all, folks!" - -# We'll use the same routing key for all messages in the loop, and -# also for the terminating message. # usa.news @@ -49,22 +45,13 @@ for i in range(5): message["routing_key"] = "usa.news" session.message_transfer(destination="amq.topic", content=message) -message = Content(final) -message["routing_key"] = "usa.news" -session.message_transfer(destination="amq.topic", content=message) - # usa.weather - for i in range(5): message = Content("message " + str(i)) message["routing_key"] = "usa.weather" session.message_transfer(destination="amq.topic", content=message) -message = Content(final) -message["routing_key"] = "usa.weather" -session.message_transfer(destination="amq.topic", content=message) - # europe.news for i in range(5): @@ -72,11 +59,6 @@ for i in range(5): message["routing_key"] = "europe.news" session.message_transfer(destination="amq.topic", content=message) -message = Content(final) -message["routing_key"] = "europe.news" -session.message_transfer(destination="amq.topic", content=message) - - # europe.weather for i in range(5): @@ -84,8 +66,10 @@ for i in range(5): message["routing_key"] = "europe.weather" session.message_transfer(destination="amq.topic", content=message) -message = Content(final) -message["routing_key"] = "europe.weather" +# Signal termination + +message = Content("That's all, folks!") +message["routing_key"] = "control" session.message_transfer(destination="amq.topic", content=message) diff --git a/python/examples/pubsub/topic_consumer.py b/python/examples/pubsub/topic_subscriber.py index afe8bba91e..08682f0674 100644 --- a/python/examples/pubsub/topic_consumer.py +++ b/python/examples/pubsub/topic_subscriber.py @@ -1,10 +1,9 @@ #!/usr/bin/env python """ - topic_consumer.py + topic_subscriber.py - This AMQP client reads all messages from the - "news", "weather", "usa", and "europe" queues - created and bound by config_topic_exchange.py. + This subscriber creates private queues and binds them + to the topics "usa.#", "europe.#", "#.news", and "#.weather". """ import base64 @@ -100,6 +99,13 @@ session.queue_bind(exchange="amq.topic", queue=weather, routing_key="#.weather") session.queue_bind(exchange="amq.topic", queue=usa, routing_key="usa.#") session.queue_bind(exchange="amq.topic", queue=europe, routing_key="europe.#") +# Bind each queue to the control queue so we know when to stop + +session.queue_bind(exchange="amq.topic", queue=news, routing_key="control") +session.queue_bind(exchange="amq.topic", queue=weather, routing_key="control") +session.queue_bind(exchange="amq.topic", queue=usa, routing_key="control") +session.queue_bind(exchange="amq.topic", queue=europe, routing_key="control") + # Remind the user to start the topic producer print "Queues create - please start the topic producer" |