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 | a8cfd6ce0dd80f4e2980f48282d074aef53f8132 (patch) | |
| tree | cb91e40edeb86443382bdbf071270f86eea8f9a3 /qpid/python/examples/pubsub/topic_publisher.py | |
| parent | b4953dd742da8c4729632ce2b6d99ebb0c8f9b32 (diff) | |
| download | qpid-python-a8cfd6ce0dd80f4e2980f48282d074aef53f8132.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@605599 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/python/examples/pubsub/topic_publisher.py')
| -rw-r--r-- | qpid/python/examples/pubsub/topic_publisher.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/qpid/python/examples/pubsub/topic_publisher.py b/qpid/python/examples/pubsub/topic_publisher.py new file mode 100644 index 0000000000..1ff983b315 --- /dev/null +++ b/qpid/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() |
