diff options
Diffstat (limited to 'python/examples/pubsub/topic_publisher.py')
| -rwxr-xr-x | python/examples/pubsub/topic_publisher.py | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/python/examples/pubsub/topic_publisher.py b/python/examples/pubsub/topic_publisher.py index b79896eaf6..64e5a99924 100755 --- a/python/examples/pubsub/topic_publisher.py +++ b/python/examples/pubsub/topic_publisher.py @@ -10,20 +10,38 @@ import qpid import sys import os -from random import randint from qpid.util import connect from qpid.connection import Connection -from qpid.datatypes import Message +from qpid.datatypes import Message, RangedSet, uuid4 from qpid.queue import Empty +#----- Functions ---------------------------------------- + +def send_msg(routing_key): + props = session.delivery_properties(routing_key=routing_key) + for i in range(5): + session.message_transfer(destination="amq.topic", message=Message(props,routing_key + " " + str(i))) + #----- Initialization ----------------------------------- -# Set parameters for login. -host=len(sys.argv) > 1 and sys.argv[1] or "127.0.0.1" -port=len(sys.argv) > 2 and int(sys.argv[2]) or 5672 +# Set parameters for login + +host="127.0.0.1" +port=5672 user="guest" password="guest" -amqp_spec="" +amqp_spec="/usr/share/amqp/amqp.0-10.xml" + +# If an alternate host or port has been specified, use that instead +# (this is used in our unit tests) +# +# If AMQP_SPEC is defined, use it to locate the spec file instead of +# looking for it in the default location. + +if len(sys.argv) > 1 : + host=sys.argv[1] +if len(sys.argv) > 2 : + port=int(sys.argv[2]) try: amqp_spec = os.environ["AMQP_SPEC"] @@ -31,10 +49,10 @@ except KeyError: amqp_spec="/usr/share/amqp/amqp.0-10.xml" # Create a connection. -conn = Connection (connect (host,port), qpid.spec.load(amqp_spec)) -conn.start() - -session = conn.session(str(randint(1,64*1024))) +socket = connect(host, port) +connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection.start() +session = connection.session(str(uuid4())) #----- Publish some messages ------------------------------ @@ -42,11 +60,6 @@ session = conn.session(str(randint(1,64*1024))) # topic exchange. The routing keys are "usa.news", "usa.weather", # "europe.news", and "europe.weather". -def send_msg(routing_key): - props = session.delivery_properties(routing_key=routing_key) - for i in range(5): - session.message_transfer("amq.topic", None, None, Message(props,"message " + str(i))) - # usa.news send_msg("usa.news") @@ -61,7 +74,7 @@ send_msg("europe.weather") # Signal termination props = session.delivery_properties(routing_key="control") -session.message_transfer("amq.topic",None, None, Message(props,"That's all, folks!")) +session.message_transfer(destination="amq.topic", message=Message(props,"That's all, folks!")) #----- Cleanup -------------------------------------------- |
