diff options
| author | Gordon Sim <gsim@apache.org> | 2007-12-19 16:01:28 +0000 |
|---|---|---|
| committer | Gordon Sim <gsim@apache.org> | 2007-12-19 16:01:28 +0000 |
| commit | 79c1bec8dd57875c2dca25bcfa500ecbf19aab5e (patch) | |
| tree | 45c3a6e3e3d17d6db5220576c53d031be175fd82 /python/examples/pubsub/topic_publisher.py | |
| parent | 62050e06a6dbe1fa22b109a9f9aea0d7d38c64ed (diff) | |
| download | qpid-python-79c1bec8dd57875c2dca25bcfa500ecbf19aab5e.tar.gz | |
File rename to better fit the pubsub nomenclature (from jrobie@redhat.com)
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@605599 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python/examples/pubsub/topic_publisher.py')
| -rw-r--r-- | python/examples/pubsub/topic_publisher.py | 80 |
1 files changed, 80 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..1ff983b315 --- /dev/null +++ b/python/examples/pubsub/topic_publisher.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python +""" + topic_publisher.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". + + +# 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) + +# 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) + +# 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) + +# 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) + +# Signal termination + +message = Content("That's all, folks!") +message["routing_key"] = "control" +session.message_transfer(destination="amq.topic", content=message) + + +#----- Cleanup -------------------------------------------- + +# Clean up before exiting so there are no open threads. + +session.session_close() |
