summaryrefslogtreecommitdiff
path: root/python/examples/pubsub/topic_publisher.py
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2007-12-05 16:22:50 +0000
committerGordon Sim <gsim@apache.org>2007-12-05 16:22:50 +0000
commitfc9c4d0d6012e7f3f92ad6ef85b0bd6b91ff46c5 (patch)
tree06959097563c7390d705419ae38a1255c3acfd6a /python/examples/pubsub/topic_publisher.py
parent8946172a6b0974ca0e0d621296e3c6619d3e3c33 (diff)
downloadqpid-python-fc9c4d0d6012e7f3f92ad6ef85b0bd6b91ff46c5.tar.gz
Renamed for consistency with c++
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@601394 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python/examples/pubsub/topic_publisher.py')
-rw-r--r--python/examples/pubsub/topic_publisher.py96
1 files changed, 96 insertions, 0 deletions
diff --git a/python/examples/pubsub/topic_publisher.py b/python/examples/pubsub/topic_publisher.py
new file mode 100644
index 0000000000..c3b13cd82c
--- /dev/null
+++ b/python/examples/pubsub/topic_publisher.py
@@ -0,0 +1,96 @@
+#!/usr/bin/env python
+"""
+ topic_producer.py
+
+ This is a simple AMQP publisher application that uses a
+ Topic exchange. The publisher specifies the routing key
+ and the exchange for each message.
+"""
+
+import qpid
+from qpid.client import Client
+from qpid.content import Content
+from qpid.queue import Empty
+
+#----- Initialization -----------------------------------
+
+# Set parameters for login.
+
+host="127.0.0.1"
+port=5672
+amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml"
+user="guest"
+password="guest"
+
+# Create a client and log in to it.
+
+spec = qpid.spec.load(amqp_spec)
+client = Client(host, port, spec)
+client.start({"LOGIN": user, "PASSWORD": password})
+
+session = client.session()
+session.session_open()
+
+#----- Publish some messages ------------------------------
+
+# Create some messages and put them on the broker. Use the
+# 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
+
+for i in range(5):
+ message = Content("message " + str(i))
+ 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):
+ message = Content("message " + str(i))
+ 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):
+ message = Content("message " + str(i))
+ message["routing_key"] = "europe.weather"
+ session.message_transfer(destination="amq.topic", content=message)
+
+message = Content(final)
+message["routing_key"] = "europe.weather"
+session.message_transfer(destination="amq.topic", content=message)
+
+
+#----- Cleanup --------------------------------------------
+
+# Clean up before exiting so there are no open threads.
+
+session.session_close()