From cbe6690289988a6e5fda4d562352394e9b1a72c7 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Fri, 30 Nov 2007 17:11:47 +0000 Subject: Python examples git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@599876 13f79535-47bb-0310-9956-ffa450edef68 --- .../examples/direct/config_direct_exchange.py | 57 ++++++++++ qpid/python/examples/direct/direct_consumer.py | 75 +++++++++++++ qpid/python/examples/direct/direct_producer.py | 51 +++++++++ .../examples/fanout/config_fanout_exchange.py | 54 ++++++++++ qpid/python/examples/fanout/fanout_consumer.py | 75 +++++++++++++ qpid/python/examples/fanout/fanout_producer.py | 49 +++++++++ qpid/python/examples/pubsub/topic_consumer.py | 120 +++++++++++++++++++++ qpid/python/examples/pubsub/topic_producer.py | 100 +++++++++++++++++ qpid/python/examples/request-response/client.py | 112 +++++++++++++++++++ qpid/python/examples/request-response/server.py | 89 +++++++++++++++ 10 files changed, 782 insertions(+) create mode 100644 qpid/python/examples/direct/config_direct_exchange.py create mode 100644 qpid/python/examples/direct/direct_consumer.py create mode 100644 qpid/python/examples/direct/direct_producer.py create mode 100644 qpid/python/examples/fanout/config_fanout_exchange.py create mode 100644 qpid/python/examples/fanout/fanout_consumer.py create mode 100644 qpid/python/examples/fanout/fanout_producer.py create mode 100644 qpid/python/examples/pubsub/topic_consumer.py create mode 100644 qpid/python/examples/pubsub/topic_producer.py create mode 100644 qpid/python/examples/request-response/client.py create mode 100644 qpid/python/examples/request-response/server.py (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/direct/config_direct_exchange.py b/qpid/python/examples/direct/config_direct_exchange.py new file mode 100644 index 0000000000..45af6f63b9 --- /dev/null +++ b/qpid/python/examples/direct/config_direct_exchange.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +""" + config_direct_exchange.py + + Creates and binds a queue on an AMQP direct exchange. + + All messages using the routing key "routing_key" are + sent to the queue named "message_queue". +""" + +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. + +client = Client(host, port, qpid.spec.load(amqp_spec)) +client.start({"LOGIN": user, "PASSWORD": password}) + +session = client.session() +session.session_open() + +#----- Create a queue ------------------------------------- + +# Create a queue named "listener" on channel 1, and bind it +# to the "amq.direct" exchange. +# +# queue_declare() creates an AMQP queue, which is held +# on the broker. Published messages are sent to the AMQP queue, +# from which messages are delivered to consumers. +# +# queue_bind() determines which messages are routed to a queue. +# Route all messages with the routing key "routing_key" to +# the AMQP queue named "message_queue". + +session.queue_declare(queue="message_queue") +session.queue_bind(exchange="amq.direct", queue="message_queue", routing_key="routing_key") + +#----- Cleanup --------------------------------------------- + +# Clean up before exiting so there are no open threads. +# +# Close Channel 1. +# Close the connection using Channel 0, which is used for all connection methods. +session.session_close() + diff --git a/qpid/python/examples/direct/direct_consumer.py b/qpid/python/examples/direct/direct_consumer.py new file mode 100644 index 0000000000..4e50dfbc2a --- /dev/null +++ b/qpid/python/examples/direct/direct_consumer.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +""" + direct_consumer.py + + This AMQP client reads messages from a message + queue named "message_queue". +""" + +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. + +client = Client(host, port, qpid.spec.load(amqp_spec)) +client.start({"LOGIN": user, "PASSWORD": password}) + +session = client.session() +session.session_open() + +#----- Read from queue -------------------------------------------- + +# Now let's create a local client queue and tell it to read +# incoming messages. + +# The consumer tag identifies the client-side queue. + +consumer_tag = "consumer1" +queue = client.queue(consumer_tag) + +# Call message_consume() to tell the broker to deliver messages +# from the AMQP queue to this local client queue. The broker will +# start delivering messages as soon as message_consume() is called. + +session.message_subscribe(queue="message_queue", destination=consumer_tag) +session.message_flow(consumer_tag, 0, 0xFFFFFFFF) # Kill these? +session.message_flow(consumer_tag, 1, 0xFFFFFFFF) # Kill these? + +# Initialize 'final' and 'content', variables used to identify the last message. + +final = "That's all, folks!" # In a message body, signals the last message +content = "" # Content of the last message read + +message = None +while content != final: + message = queue.get(timeout=10) + content = message.content.body + print content + +# Messages are not removed from the queue until they are +# acknowledged. Using cumulative=True, all messages from the session +# up to and including the one identified by the delivery tag are +# acknowledged. This is more efficient, because there are fewer +# network round-trips. + +message.complete(cumulative=True) + +#----- Cleanup ------------------------------------------------ + +# Clean up before exiting so there are no open threads. +# + +# session.session_close() diff --git a/qpid/python/examples/direct/direct_producer.py b/qpid/python/examples/direct/direct_producer.py new file mode 100644 index 0000000000..6770e56803 --- /dev/null +++ b/qpid/python/examples/direct/direct_producer.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +""" + direct_producer.py + + Publishes messages to an AMQP direct exchange, using + the routing key "routing_key" +""" + +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. + +client = Client(host, port, qpid.spec.load(amqp_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. + +for i in range(10): + message = Content("message " + str(i)) + message["routing_key"] = "routing_key" + session.message_transfer(destination="amq.direct", content=message) + +final="That's all, folks!" +message = Content(final) +message["routing_key"] = "routing_key" +session.message_transfer(destination="amq.direct", content=message) + +#----- Cleanup -------------------------------------------- + +# Clean up before exiting so there are no open threads. + +session.session_close() + diff --git a/qpid/python/examples/fanout/config_fanout_exchange.py b/qpid/python/examples/fanout/config_fanout_exchange.py new file mode 100644 index 0000000000..6eef1b94e3 --- /dev/null +++ b/qpid/python/examples/fanout/config_fanout_exchange.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python +""" + config_direct_exchange.py + + Creates and binds a queue on an AMQP direct exchange. + + All messages using the routing key "routing_key" are + sent to the queue named "message_queue". +""" + +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. + +client = Client(host, port, qpid.spec.load(amqp_spec)) +client.start({"LOGIN": user, "PASSWORD": password}) + +session = client.session() +session.session_open() + +#----- Create a queue ------------------------------------- + +# Create a queue named "listener" on channel 1, and bind it +# to the "amq.fanout" exchange. +# +# queue_declare() creates an AMQP queue, which is held +# on the broker. Published messages are sent to the AMQP queue, +# from which messages are delivered to consumers. +# +# queue_bind() determines which messages are routed to a queue. +# Route all messages with the routing key "routing_key" to +# the AMQP queue named "message_queue". + +session.queue_declare(queue="message_queue") +session.queue_bind(exchange="amq.fanout", queue="message_queue") + +#----- Cleanup --------------------------------------------- + +# Clean up before exiting so there are no open threads. +# channel.session_close() + diff --git a/qpid/python/examples/fanout/fanout_consumer.py b/qpid/python/examples/fanout/fanout_consumer.py new file mode 100644 index 0000000000..e9a2291f4c --- /dev/null +++ b/qpid/python/examples/fanout/fanout_consumer.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +""" + direct_consumer.py + + This AMQP client reads messages from a message + queue named "message_queue". +""" + +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. + +client = Client(host, port, qpid.spec.load(amqp_spec)) +client.start({"LOGIN": user, "PASSWORD": password}) + +session = client.session() +session.session_open() + +#----- Read from queue -------------------------------------------- + +# Now let's create a local client queue and tell it to read +# incoming messages. + +# The consumer tag identifies the client-side queue. + +consumer_tag = "consumer1" +queue = client.queue(consumer_tag) + +# Call message_consume() to tell the broker to deliver messages +# from the AMQP queue to this local client queue. The broker will +# start delivering messages as soon as message_consume() is called. + +session.message_subscribe(queue="message_queue", destination=consumer_tag) +session.message_flow(consumer_tag, 0, 0xFFFFFFFF) +session.message_flow(consumer_tag, 1, 0xFFFFFFFF) + +# Initialize 'final' and 'content', variables used to identify the last message. + +final = "That's all, folks!" # In a message body, signals the last message +content = "" # Content of the last message read + +message = None +while content != final: + message = queue.get(timeout=10) + content = message.content.body + print content + +# Messages are not removed from the queue until they are +# acknowledged. Using cumulative=True, all messages from the session +# up to and including the one identified by the delivery tag are +# acknowledged. This is more efficient, because there are fewer +# network round-trips. + +message.complete(cumulative=True) + +#----- Cleanup ------------------------------------------------ + +# Clean up before exiting so there are no open threads. +# + +session.session_close() diff --git a/qpid/python/examples/fanout/fanout_producer.py b/qpid/python/examples/fanout/fanout_producer.py new file mode 100644 index 0000000000..42570ed510 --- /dev/null +++ b/qpid/python/examples/fanout/fanout_producer.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +""" + direct_producer.py + + Publishes messages to an AMQP direct exchange, using + the routing key "routing_key" +""" + +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. + +client = Client(host, port, qpid.spec.load(amqp_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. + +for i in range(10): + message = Content(body="message " + str(i)) + session.message_transfer(destination="amq.fanout", content=message) + +final="That's all, folks!" +message=Content(final) +session.message_transfer(destination="amq.fanout", content=message) + +#----- Cleanup -------------------------------------------- + +# Clean up before exiting so there are no open threads. + +session.session_close() + diff --git a/qpid/python/examples/pubsub/topic_consumer.py b/qpid/python/examples/pubsub/topic_consumer.py new file mode 100644 index 0000000000..5db04573f8 --- /dev/null +++ b/qpid/python/examples/pubsub/topic_consumer.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python +""" + topic_consumer.py + + This AMQP client reads all messages from the + "news", "weather", "usa", and "europe" queues + created and bound by config_topic_exchange.py. +""" + +import base64 + +import qpid +from qpid.client import Client +from qpid.content import Content +from qpid.queue import Empty + +#----- Functions ------------------------------------------- + +def dump_queue(client, queue_name): + + print "Messages queue: " + queue_name + + consumer_tag = queue_name # Use the queue name as the consumer tag - need a unique tag + queue = client.queue(consumer_tag) + + # Call basic_consume() to tell the broker to deliver messages + # from the AMQP queue to a local client queue. The broker will + # start delivering messages as soon as basic_consume() is called. + + session.message_subscribe(queue=queue_name, destination=consumer_tag) + session.message_flow(consumer_tag, 0, 0xFFFFFFFF) + session.message_flow(consumer_tag, 1, 0xFFFFFFFF) + + content = "" # Content of the last message read + final = "That's all, folks!" # In a message body, signals the last message + message = 0 + + while content != final: + try: + message = queue.get() + content = message.content.body + print content + except Empty: + if message != 0: + message.complete(cumulative=True) + print "No more messages!" + return + + + # Messages are not removed from the queue until they + # are acknowledged. Using multiple=True, all messages + # in the channel up to and including the one identified + # by the delivery tag are acknowledged. This is more efficient, + # because there are fewer network round-trips. + + if message != 0: + message.complete(cumulative=True) + + +#----- 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.session_open() # keep the session object, we'll need the session id + +#----- Main Body -- ---------------------------------------- + + +news = "news" + base64.urlsafe_b64encode(session.session_id) +weather = "weather" + base64.urlsafe_b64encode(session.session_id) +usa = "usa" + base64.urlsafe_b64encode(session.session_id) +europe = "europe" + base64.urlsafe_b64encode(session.session_id) + +session.queue_declare(queue=news, exclusive=True) +session.queue_declare(queue=weather, exclusive=True) +session.queue_declare(queue=usa, exclusive=True) +session.queue_declare(queue=europe, exclusive=True) + +# Routing keys may be "usa.news", "usa.weather", "europe.news", or "europe.weather". + +# The '#' symbol matches one component of a multipart name, e.g. "#.news" matches +# "europe.news" or "usa.news". + +session.queue_bind(exchange="amq.topic", queue=news, routing_key="#.news") +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.#") + +# Remind the user to start the topic producer + +print "Queues create - please start the topic producer" + +# Call dump_queue to print messages from each queue + +dump_queue(client, news) +dump_queue(client, weather) +dump_queue(client, usa) +dump_queue(client, europe) + +#----- Cleanup ------------------------------------------------ + +# Clean up before exiting so there are no open threads. +# +# Close Channel 1. + +session.session_close() + diff --git a/qpid/python/examples/pubsub/topic_producer.py b/qpid/python/examples/pubsub/topic_producer.py new file mode 100644 index 0000000000..5f8372e7ba --- /dev/null +++ b/qpid/python/examples/pubsub/topic_producer.py @@ -0,0 +1,100 @@ +#!/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. +# +# Close Channel 1. + + +session.session_close() + diff --git a/qpid/python/examples/request-response/client.py b/qpid/python/examples/request-response/client.py new file mode 100644 index 0000000000..23e9310509 --- /dev/null +++ b/qpid/python/examples/request-response/client.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python +""" + client.py + + Client for a client/server example + +""" + +import base64 + +import qpid +from qpid.client import Client +from qpid.content import Content +from qpid.queue import Empty + +#----- Functions ------------------------------------------- + +def dump_queue(client, queue_name): + + print "Messages queue: " + queue_name + + consumer_tag = queue_name # Use the queue name as the consumer tag - need a unique tag + queue = client.queue(consumer_tag) + + # Call basic_consume() to tell the broker to deliver messages + # from the AMQP queue to a local client queue. The broker will + # start delivering messages as soon as basic_consume() is called. + + session.message_subscribe(queue=queue_name, destination=consumer_tag) + session.message_flow(consumer_tag, 0, 0xFFFFFFFF) + session.message_flow(consumer_tag, 1, 0xFFFFFFFF) + + message = 0 + + while True: + try: + message = queue.get(timeout=10) + content = message.content.body + print "Response: " + content + except Empty: + print "No more messages!" + break + except: + print "Unexpected exception!" + break + + + # Messages are not removed from the queue until they + # are acknowledged. Using multiple=True, all messages + # in the channel up to and including the one identified + # by the delivery tag are acknowledged. This is more efficient, + # because there are fewer network round-trips. + + if message != 0: + message.complete(cumulative=True) + + +#----- 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() + +#----- Main Body -- ---------------------------------------- + +# Create a response queue for the server to send responses to. Use the +# same string as the name of the queue and the name of the routing +# key. + +replyTo = "ReplyTo:" # + base64.urlsafe_b64encode(session.session_id) +session.queue_declare(queue=replyTo, exclusive=True) +session.queue_bind(exchange="amq.direct", queue=replyTo, routing_key=replyTo) + +# Send some messages to the server's request queue + +lines = ["Twas brilling, and the slithy toves", + "Did gyre and gimble in the wabe.", + "All mimsy were the borogroves,", + "And the mome raths outgrabe."] + +for l in lines: + print "Request: " + l + request=Content(l) + request["routing_key"] = "request" + request["reply_to"] = client.spec.struct("reply_to") + request["reply_to"]["exchange_name"] = "amq.direct" + request["reply_to"]["routing_key"] = replyTo + session.message_transfer(destination="amq.direct", content=request) + +# Now see what messages the server sent to our replyTo queue + +dump_queue(client, replyTo) + + +#----- Cleanup ------------------------------------------------ + +# Clean up before exiting so there are no open threads. + +session.session_close() diff --git a/qpid/python/examples/request-response/server.py b/qpid/python/examples/request-response/server.py new file mode 100644 index 0000000000..dd81b419e8 --- /dev/null +++ b/qpid/python/examples/request-response/server.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python +""" + server.py + + Server for a client/server example +""" + +import qpid +from qpid.client import Client +from qpid.content import Content +from qpid.queue import Empty + +#----- Functions ------------------------------------------- + +def respond(session, request): + + # The routing key for the response is the request's reply-to + # property. The body for the response is the request's body, + # converted to upper case. + + response=Content(request.body.upper()) + response["routing_key"] = request["reply_to"]["routing_key"] + + session.message_transfer(destination=request["reply_to"]["exchange_name"], content=response) + +#----- 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. + +client = Client(host, port, qpid.spec.load(amqp_spec)) +client.start({"LOGIN": user, "PASSWORD": password}) + +# Open Channel 1 so we can use it to manage our queue. + +session = client.session() +session.session_open() # keep the session object, we'll need the session id + +#----- Main Body -- ---------------------------------------- + +# Create a request queue and subscribe to it + +session.queue_declare(queue="request", exclusive=True) +session.queue_bind(exchange="amq.direct", queue="request", routing_key="request") + +dest = "request_destination" + +session.message_subscribe(queue="request", destination=dest) +session.message_flow(dest, 0, 0xFFFFFFFF) +session.message_flow(dest, 1, 0xFFFFFFFF) + + +# Remind the user to start the client program + +print "Request server running - run your client now." +print "(Times out after 100 seconds ...)" + +# Respond to each request + +queue = client.queue(dest) + +# If we get a message, send it back to the user (as indicated in the +# ReplyTo property) + +while True: + try: + request = queue.get(timeout=100) + respond(session, request.content) + request.complete() + except Empty: + print "No more messages!" + break; + + +#----- Cleanup ------------------------------------------------ + +# Clean up before exiting so there are no open threads. +# +# Close Channel 1. + +session.session_close() + -- cgit v1.2.1 From 387a53a7dd18dd0bd3dd4a36b2a600cfbd60f249 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Wed, 5 Dec 2007 15:19:45 +0000 Subject: Updates to examples from jonathan.robie@redhat.com git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@601358 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/direct/config_direct_exchange.py | 4 ---- qpid/python/examples/direct/direct_consumer.py | 2 +- qpid/python/examples/fanout/config_fanout_exchange.py | 2 +- qpid/python/examples/fanout/fanout_producer.py | 1 - qpid/python/examples/pubsub/topic_consumer.py | 14 ++++++-------- qpid/python/examples/pubsub/topic_producer.py | 4 ---- qpid/python/examples/request-response/client.py | 15 +++++++++------ qpid/python/examples/request-response/server.py | 5 +---- 8 files changed, 18 insertions(+), 29 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/direct/config_direct_exchange.py b/qpid/python/examples/direct/config_direct_exchange.py index 45af6f63b9..e64ad678b8 100644 --- a/qpid/python/examples/direct/config_direct_exchange.py +++ b/qpid/python/examples/direct/config_direct_exchange.py @@ -49,9 +49,5 @@ session.queue_bind(exchange="amq.direct", queue="message_queue", routing_key="ro #----- Cleanup --------------------------------------------- -# Clean up before exiting so there are no open threads. -# -# Close Channel 1. -# Close the connection using Channel 0, which is used for all connection methods. session.session_close() diff --git a/qpid/python/examples/direct/direct_consumer.py b/qpid/python/examples/direct/direct_consumer.py index 4e50dfbc2a..38b1ba30a0 100644 --- a/qpid/python/examples/direct/direct_consumer.py +++ b/qpid/python/examples/direct/direct_consumer.py @@ -72,4 +72,4 @@ message.complete(cumulative=True) # Clean up before exiting so there are no open threads. # -# session.session_close() +session.session_close() diff --git a/qpid/python/examples/fanout/config_fanout_exchange.py b/qpid/python/examples/fanout/config_fanout_exchange.py index 6eef1b94e3..3315f5bc14 100644 --- a/qpid/python/examples/fanout/config_fanout_exchange.py +++ b/qpid/python/examples/fanout/config_fanout_exchange.py @@ -50,5 +50,5 @@ session.queue_bind(exchange="amq.fanout", queue="message_queue") #----- Cleanup --------------------------------------------- # Clean up before exiting so there are no open threads. -# channel.session_close() +session.session_close() diff --git a/qpid/python/examples/fanout/fanout_producer.py b/qpid/python/examples/fanout/fanout_producer.py index 42570ed510..92ca7b7ec0 100644 --- a/qpid/python/examples/fanout/fanout_producer.py +++ b/qpid/python/examples/fanout/fanout_producer.py @@ -46,4 +46,3 @@ session.message_transfer(destination="amq.fanout", content=message) # Clean up before exiting so there are no open threads. session.session_close() - diff --git a/qpid/python/examples/pubsub/topic_consumer.py b/qpid/python/examples/pubsub/topic_consumer.py index 5db04573f8..afe8bba91e 100644 --- a/qpid/python/examples/pubsub/topic_consumer.py +++ b/qpid/python/examples/pubsub/topic_consumer.py @@ -74,15 +74,16 @@ client = Client(host, port, spec) client.start({"LOGIN": user, "PASSWORD": password}) session = client.session() -session = session.session_open() # keep the session object, we'll need the session id +session_info = session.session_open() +session_id = session_info.session_id #----- Main Body -- ---------------------------------------- -news = "news" + base64.urlsafe_b64encode(session.session_id) -weather = "weather" + base64.urlsafe_b64encode(session.session_id) -usa = "usa" + base64.urlsafe_b64encode(session.session_id) -europe = "europe" + base64.urlsafe_b64encode(session.session_id) +news = "news" + base64.urlsafe_b64encode(session_id) +weather = "weather" + base64.urlsafe_b64encode(session_id) +usa = "usa" + base64.urlsafe_b64encode(session_id) +europe = "europe" + base64.urlsafe_b64encode(session_id) session.queue_declare(queue=news, exclusive=True) session.queue_declare(queue=weather, exclusive=True) @@ -113,8 +114,5 @@ dump_queue(client, europe) #----- Cleanup ------------------------------------------------ # Clean up before exiting so there are no open threads. -# -# Close Channel 1. session.session_close() - diff --git a/qpid/python/examples/pubsub/topic_producer.py b/qpid/python/examples/pubsub/topic_producer.py index 5f8372e7ba..c3b13cd82c 100644 --- a/qpid/python/examples/pubsub/topic_producer.py +++ b/qpid/python/examples/pubsub/topic_producer.py @@ -92,9 +92,5 @@ session.message_transfer(destination="amq.topic", content=message) #----- Cleanup -------------------------------------------- # Clean up before exiting so there are no open threads. -# -# Close Channel 1. - session.session_close() - diff --git a/qpid/python/examples/request-response/client.py b/qpid/python/examples/request-response/client.py index 23e9310509..bc0cf8a55a 100644 --- a/qpid/python/examples/request-response/client.py +++ b/qpid/python/examples/request-response/client.py @@ -22,7 +22,7 @@ def dump_queue(client, queue_name): consumer_tag = queue_name # Use the queue name as the consumer tag - need a unique tag queue = client.queue(consumer_tag) - # Call basic_consume() to tell the broker to deliver messages + # Call message_subscribe() to tell the broker to deliver messages # from the AMQP queue to a local client queue. The broker will # start delivering messages as soon as basic_consume() is called. @@ -46,8 +46,8 @@ def dump_queue(client, queue_name): # Messages are not removed from the queue until they - # are acknowledged. Using multiple=True, all messages - # in the channel up to and including the one identified + # are acknowledged. Using cumulative=True, all messages + # in the session up to and including the one identified # by the delivery tag are acknowledged. This is more efficient, # because there are fewer network round-trips. @@ -71,8 +71,11 @@ spec = qpid.spec.load(amqp_spec) client = Client(host, port, spec) client.start({"LOGIN": user, "PASSWORD": password}) +# Open the session. Save the session id. + session = client.session() -session.session_open() +session_info = session.session_open() +session_id = session_info.session_id #----- Main Body -- ---------------------------------------- @@ -80,7 +83,7 @@ session.session_open() # same string as the name of the queue and the name of the routing # key. -replyTo = "ReplyTo:" # + base64.urlsafe_b64encode(session.session_id) +replyTo = "ReplyTo:" + base64.urlsafe_b64encode(session_id) session.queue_declare(queue=replyTo, exclusive=True) session.queue_bind(exchange="amq.direct", queue=replyTo, routing_key=replyTo) @@ -109,4 +112,4 @@ dump_queue(client, replyTo) # Clean up before exiting so there are no open threads. -session.session_close() +session.session_close() diff --git a/qpid/python/examples/request-response/server.py b/qpid/python/examples/request-response/server.py index dd81b419e8..28bfd5ee4a 100644 --- a/qpid/python/examples/request-response/server.py +++ b/qpid/python/examples/request-response/server.py @@ -41,7 +41,7 @@ client.start({"LOGIN": user, "PASSWORD": password}) # Open Channel 1 so we can use it to manage our queue. session = client.session() -session.session_open() # keep the session object, we'll need the session id +session.session_open() #----- Main Body -- ---------------------------------------- @@ -82,8 +82,5 @@ while True: #----- Cleanup ------------------------------------------------ # Clean up before exiting so there are no open threads. -# -# Close Channel 1. session.session_close() - -- cgit v1.2.1 From 46989a4ce0c90b73dbcb76cb344c95b0de27d360 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Wed, 5 Dec 2007 16:22:50 +0000 Subject: Renamed for consistency with c++ git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@601394 13f79535-47bb-0310-9956-ffa450edef68 --- .../examples/direct/config_direct_exchange.py | 53 --------- .../python/examples/direct/direct_config_queues.py | 53 +++++++++ qpid/python/examples/direct/direct_consumer.py | 75 ------------- qpid/python/examples/direct/direct_producer.py | 51 --------- qpid/python/examples/direct/direct_publisher.py | 51 +++++++++ qpid/python/examples/direct/listener.py | 75 +++++++++++++ .../examples/fanout/config_fanout_exchange.py | 54 ---------- .../python/examples/fanout/fanout_config_queues.py | 54 ++++++++++ qpid/python/examples/fanout/fanout_consumer.py | 75 ------------- qpid/python/examples/fanout/fanout_producer.py | 48 --------- qpid/python/examples/fanout/fanout_publisher.py | 48 +++++++++ qpid/python/examples/fanout/listener.py | 75 +++++++++++++ qpid/python/examples/pubsub/topic_consumer.py | 118 --------------------- qpid/python/examples/pubsub/topic_listener.py | 118 +++++++++++++++++++++ qpid/python/examples/pubsub/topic_producer.py | 96 ----------------- qpid/python/examples/pubsub/topic_publisher.py | 96 +++++++++++++++++ 16 files changed, 570 insertions(+), 570 deletions(-) delete mode 100644 qpid/python/examples/direct/config_direct_exchange.py create mode 100644 qpid/python/examples/direct/direct_config_queues.py delete mode 100644 qpid/python/examples/direct/direct_consumer.py delete mode 100644 qpid/python/examples/direct/direct_producer.py create mode 100644 qpid/python/examples/direct/direct_publisher.py create mode 100644 qpid/python/examples/direct/listener.py delete mode 100644 qpid/python/examples/fanout/config_fanout_exchange.py create mode 100644 qpid/python/examples/fanout/fanout_config_queues.py delete mode 100644 qpid/python/examples/fanout/fanout_consumer.py delete mode 100644 qpid/python/examples/fanout/fanout_producer.py create mode 100644 qpid/python/examples/fanout/fanout_publisher.py create mode 100644 qpid/python/examples/fanout/listener.py delete mode 100644 qpid/python/examples/pubsub/topic_consumer.py create mode 100644 qpid/python/examples/pubsub/topic_listener.py delete mode 100644 qpid/python/examples/pubsub/topic_producer.py create mode 100644 qpid/python/examples/pubsub/topic_publisher.py (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/direct/config_direct_exchange.py b/qpid/python/examples/direct/config_direct_exchange.py deleted file mode 100644 index e64ad678b8..0000000000 --- a/qpid/python/examples/direct/config_direct_exchange.py +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env python -""" - config_direct_exchange.py - - Creates and binds a queue on an AMQP direct exchange. - - All messages using the routing key "routing_key" are - sent to the queue named "message_queue". -""" - -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. - -client = Client(host, port, qpid.spec.load(amqp_spec)) -client.start({"LOGIN": user, "PASSWORD": password}) - -session = client.session() -session.session_open() - -#----- Create a queue ------------------------------------- - -# Create a queue named "listener" on channel 1, and bind it -# to the "amq.direct" exchange. -# -# queue_declare() creates an AMQP queue, which is held -# on the broker. Published messages are sent to the AMQP queue, -# from which messages are delivered to consumers. -# -# queue_bind() determines which messages are routed to a queue. -# Route all messages with the routing key "routing_key" to -# the AMQP queue named "message_queue". - -session.queue_declare(queue="message_queue") -session.queue_bind(exchange="amq.direct", queue="message_queue", routing_key="routing_key") - -#----- Cleanup --------------------------------------------- - -session.session_close() - diff --git a/qpid/python/examples/direct/direct_config_queues.py b/qpid/python/examples/direct/direct_config_queues.py new file mode 100644 index 0000000000..e64ad678b8 --- /dev/null +++ b/qpid/python/examples/direct/direct_config_queues.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +""" + config_direct_exchange.py + + Creates and binds a queue on an AMQP direct exchange. + + All messages using the routing key "routing_key" are + sent to the queue named "message_queue". +""" + +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. + +client = Client(host, port, qpid.spec.load(amqp_spec)) +client.start({"LOGIN": user, "PASSWORD": password}) + +session = client.session() +session.session_open() + +#----- Create a queue ------------------------------------- + +# Create a queue named "listener" on channel 1, and bind it +# to the "amq.direct" exchange. +# +# queue_declare() creates an AMQP queue, which is held +# on the broker. Published messages are sent to the AMQP queue, +# from which messages are delivered to consumers. +# +# queue_bind() determines which messages are routed to a queue. +# Route all messages with the routing key "routing_key" to +# the AMQP queue named "message_queue". + +session.queue_declare(queue="message_queue") +session.queue_bind(exchange="amq.direct", queue="message_queue", routing_key="routing_key") + +#----- Cleanup --------------------------------------------- + +session.session_close() + diff --git a/qpid/python/examples/direct/direct_consumer.py b/qpid/python/examples/direct/direct_consumer.py deleted file mode 100644 index 38b1ba30a0..0000000000 --- a/qpid/python/examples/direct/direct_consumer.py +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env python -""" - direct_consumer.py - - This AMQP client reads messages from a message - queue named "message_queue". -""" - -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. - -client = Client(host, port, qpid.spec.load(amqp_spec)) -client.start({"LOGIN": user, "PASSWORD": password}) - -session = client.session() -session.session_open() - -#----- Read from queue -------------------------------------------- - -# Now let's create a local client queue and tell it to read -# incoming messages. - -# The consumer tag identifies the client-side queue. - -consumer_tag = "consumer1" -queue = client.queue(consumer_tag) - -# Call message_consume() to tell the broker to deliver messages -# from the AMQP queue to this local client queue. The broker will -# start delivering messages as soon as message_consume() is called. - -session.message_subscribe(queue="message_queue", destination=consumer_tag) -session.message_flow(consumer_tag, 0, 0xFFFFFFFF) # Kill these? -session.message_flow(consumer_tag, 1, 0xFFFFFFFF) # Kill these? - -# Initialize 'final' and 'content', variables used to identify the last message. - -final = "That's all, folks!" # In a message body, signals the last message -content = "" # Content of the last message read - -message = None -while content != final: - message = queue.get(timeout=10) - content = message.content.body - print content - -# Messages are not removed from the queue until they are -# acknowledged. Using cumulative=True, all messages from the session -# up to and including the one identified by the delivery tag are -# acknowledged. This is more efficient, because there are fewer -# network round-trips. - -message.complete(cumulative=True) - -#----- Cleanup ------------------------------------------------ - -# Clean up before exiting so there are no open threads. -# - -session.session_close() diff --git a/qpid/python/examples/direct/direct_producer.py b/qpid/python/examples/direct/direct_producer.py deleted file mode 100644 index 6770e56803..0000000000 --- a/qpid/python/examples/direct/direct_producer.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env python -""" - direct_producer.py - - Publishes messages to an AMQP direct exchange, using - the routing key "routing_key" -""" - -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. - -client = Client(host, port, qpid.spec.load(amqp_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. - -for i in range(10): - message = Content("message " + str(i)) - message["routing_key"] = "routing_key" - session.message_transfer(destination="amq.direct", content=message) - -final="That's all, folks!" -message = Content(final) -message["routing_key"] = "routing_key" -session.message_transfer(destination="amq.direct", content=message) - -#----- Cleanup -------------------------------------------- - -# Clean up before exiting so there are no open threads. - -session.session_close() - diff --git a/qpid/python/examples/direct/direct_publisher.py b/qpid/python/examples/direct/direct_publisher.py new file mode 100644 index 0000000000..6770e56803 --- /dev/null +++ b/qpid/python/examples/direct/direct_publisher.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +""" + direct_producer.py + + Publishes messages to an AMQP direct exchange, using + the routing key "routing_key" +""" + +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. + +client = Client(host, port, qpid.spec.load(amqp_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. + +for i in range(10): + message = Content("message " + str(i)) + message["routing_key"] = "routing_key" + session.message_transfer(destination="amq.direct", content=message) + +final="That's all, folks!" +message = Content(final) +message["routing_key"] = "routing_key" +session.message_transfer(destination="amq.direct", content=message) + +#----- Cleanup -------------------------------------------- + +# Clean up before exiting so there are no open threads. + +session.session_close() + diff --git a/qpid/python/examples/direct/listener.py b/qpid/python/examples/direct/listener.py new file mode 100644 index 0000000000..38b1ba30a0 --- /dev/null +++ b/qpid/python/examples/direct/listener.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +""" + direct_consumer.py + + This AMQP client reads messages from a message + queue named "message_queue". +""" + +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. + +client = Client(host, port, qpid.spec.load(amqp_spec)) +client.start({"LOGIN": user, "PASSWORD": password}) + +session = client.session() +session.session_open() + +#----- Read from queue -------------------------------------------- + +# Now let's create a local client queue and tell it to read +# incoming messages. + +# The consumer tag identifies the client-side queue. + +consumer_tag = "consumer1" +queue = client.queue(consumer_tag) + +# Call message_consume() to tell the broker to deliver messages +# from the AMQP queue to this local client queue. The broker will +# start delivering messages as soon as message_consume() is called. + +session.message_subscribe(queue="message_queue", destination=consumer_tag) +session.message_flow(consumer_tag, 0, 0xFFFFFFFF) # Kill these? +session.message_flow(consumer_tag, 1, 0xFFFFFFFF) # Kill these? + +# Initialize 'final' and 'content', variables used to identify the last message. + +final = "That's all, folks!" # In a message body, signals the last message +content = "" # Content of the last message read + +message = None +while content != final: + message = queue.get(timeout=10) + content = message.content.body + print content + +# Messages are not removed from the queue until they are +# acknowledged. Using cumulative=True, all messages from the session +# up to and including the one identified by the delivery tag are +# acknowledged. This is more efficient, because there are fewer +# network round-trips. + +message.complete(cumulative=True) + +#----- Cleanup ------------------------------------------------ + +# Clean up before exiting so there are no open threads. +# + +session.session_close() diff --git a/qpid/python/examples/fanout/config_fanout_exchange.py b/qpid/python/examples/fanout/config_fanout_exchange.py deleted file mode 100644 index 3315f5bc14..0000000000 --- a/qpid/python/examples/fanout/config_fanout_exchange.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python -""" - config_direct_exchange.py - - Creates and binds a queue on an AMQP direct exchange. - - All messages using the routing key "routing_key" are - sent to the queue named "message_queue". -""" - -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. - -client = Client(host, port, qpid.spec.load(amqp_spec)) -client.start({"LOGIN": user, "PASSWORD": password}) - -session = client.session() -session.session_open() - -#----- Create a queue ------------------------------------- - -# Create a queue named "listener" on channel 1, and bind it -# to the "amq.fanout" exchange. -# -# queue_declare() creates an AMQP queue, which is held -# on the broker. Published messages are sent to the AMQP queue, -# from which messages are delivered to consumers. -# -# queue_bind() determines which messages are routed to a queue. -# Route all messages with the routing key "routing_key" to -# the AMQP queue named "message_queue". - -session.queue_declare(queue="message_queue") -session.queue_bind(exchange="amq.fanout", queue="message_queue") - -#----- Cleanup --------------------------------------------- - -# Clean up before exiting so there are no open threads. - -session.session_close() diff --git a/qpid/python/examples/fanout/fanout_config_queues.py b/qpid/python/examples/fanout/fanout_config_queues.py new file mode 100644 index 0000000000..3315f5bc14 --- /dev/null +++ b/qpid/python/examples/fanout/fanout_config_queues.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python +""" + config_direct_exchange.py + + Creates and binds a queue on an AMQP direct exchange. + + All messages using the routing key "routing_key" are + sent to the queue named "message_queue". +""" + +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. + +client = Client(host, port, qpid.spec.load(amqp_spec)) +client.start({"LOGIN": user, "PASSWORD": password}) + +session = client.session() +session.session_open() + +#----- Create a queue ------------------------------------- + +# Create a queue named "listener" on channel 1, and bind it +# to the "amq.fanout" exchange. +# +# queue_declare() creates an AMQP queue, which is held +# on the broker. Published messages are sent to the AMQP queue, +# from which messages are delivered to consumers. +# +# queue_bind() determines which messages are routed to a queue. +# Route all messages with the routing key "routing_key" to +# the AMQP queue named "message_queue". + +session.queue_declare(queue="message_queue") +session.queue_bind(exchange="amq.fanout", queue="message_queue") + +#----- Cleanup --------------------------------------------- + +# Clean up before exiting so there are no open threads. + +session.session_close() diff --git a/qpid/python/examples/fanout/fanout_consumer.py b/qpid/python/examples/fanout/fanout_consumer.py deleted file mode 100644 index e9a2291f4c..0000000000 --- a/qpid/python/examples/fanout/fanout_consumer.py +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env python -""" - direct_consumer.py - - This AMQP client reads messages from a message - queue named "message_queue". -""" - -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. - -client = Client(host, port, qpid.spec.load(amqp_spec)) -client.start({"LOGIN": user, "PASSWORD": password}) - -session = client.session() -session.session_open() - -#----- Read from queue -------------------------------------------- - -# Now let's create a local client queue and tell it to read -# incoming messages. - -# The consumer tag identifies the client-side queue. - -consumer_tag = "consumer1" -queue = client.queue(consumer_tag) - -# Call message_consume() to tell the broker to deliver messages -# from the AMQP queue to this local client queue. The broker will -# start delivering messages as soon as message_consume() is called. - -session.message_subscribe(queue="message_queue", destination=consumer_tag) -session.message_flow(consumer_tag, 0, 0xFFFFFFFF) -session.message_flow(consumer_tag, 1, 0xFFFFFFFF) - -# Initialize 'final' and 'content', variables used to identify the last message. - -final = "That's all, folks!" # In a message body, signals the last message -content = "" # Content of the last message read - -message = None -while content != final: - message = queue.get(timeout=10) - content = message.content.body - print content - -# Messages are not removed from the queue until they are -# acknowledged. Using cumulative=True, all messages from the session -# up to and including the one identified by the delivery tag are -# acknowledged. This is more efficient, because there are fewer -# network round-trips. - -message.complete(cumulative=True) - -#----- Cleanup ------------------------------------------------ - -# Clean up before exiting so there are no open threads. -# - -session.session_close() diff --git a/qpid/python/examples/fanout/fanout_producer.py b/qpid/python/examples/fanout/fanout_producer.py deleted file mode 100644 index 92ca7b7ec0..0000000000 --- a/qpid/python/examples/fanout/fanout_producer.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python -""" - direct_producer.py - - Publishes messages to an AMQP direct exchange, using - the routing key "routing_key" -""" - -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. - -client = Client(host, port, qpid.spec.load(amqp_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. - -for i in range(10): - message = Content(body="message " + str(i)) - session.message_transfer(destination="amq.fanout", content=message) - -final="That's all, folks!" -message=Content(final) -session.message_transfer(destination="amq.fanout", content=message) - -#----- Cleanup -------------------------------------------- - -# Clean up before exiting so there are no open threads. - -session.session_close() diff --git a/qpid/python/examples/fanout/fanout_publisher.py b/qpid/python/examples/fanout/fanout_publisher.py new file mode 100644 index 0000000000..92ca7b7ec0 --- /dev/null +++ b/qpid/python/examples/fanout/fanout_publisher.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python +""" + direct_producer.py + + Publishes messages to an AMQP direct exchange, using + the routing key "routing_key" +""" + +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. + +client = Client(host, port, qpid.spec.load(amqp_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. + +for i in range(10): + message = Content(body="message " + str(i)) + session.message_transfer(destination="amq.fanout", content=message) + +final="That's all, folks!" +message=Content(final) +session.message_transfer(destination="amq.fanout", content=message) + +#----- Cleanup -------------------------------------------- + +# Clean up before exiting so there are no open threads. + +session.session_close() diff --git a/qpid/python/examples/fanout/listener.py b/qpid/python/examples/fanout/listener.py new file mode 100644 index 0000000000..e9a2291f4c --- /dev/null +++ b/qpid/python/examples/fanout/listener.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +""" + direct_consumer.py + + This AMQP client reads messages from a message + queue named "message_queue". +""" + +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. + +client = Client(host, port, qpid.spec.load(amqp_spec)) +client.start({"LOGIN": user, "PASSWORD": password}) + +session = client.session() +session.session_open() + +#----- Read from queue -------------------------------------------- + +# Now let's create a local client queue and tell it to read +# incoming messages. + +# The consumer tag identifies the client-side queue. + +consumer_tag = "consumer1" +queue = client.queue(consumer_tag) + +# Call message_consume() to tell the broker to deliver messages +# from the AMQP queue to this local client queue. The broker will +# start delivering messages as soon as message_consume() is called. + +session.message_subscribe(queue="message_queue", destination=consumer_tag) +session.message_flow(consumer_tag, 0, 0xFFFFFFFF) +session.message_flow(consumer_tag, 1, 0xFFFFFFFF) + +# Initialize 'final' and 'content', variables used to identify the last message. + +final = "That's all, folks!" # In a message body, signals the last message +content = "" # Content of the last message read + +message = None +while content != final: + message = queue.get(timeout=10) + content = message.content.body + print content + +# Messages are not removed from the queue until they are +# acknowledged. Using cumulative=True, all messages from the session +# up to and including the one identified by the delivery tag are +# acknowledged. This is more efficient, because there are fewer +# network round-trips. + +message.complete(cumulative=True) + +#----- Cleanup ------------------------------------------------ + +# Clean up before exiting so there are no open threads. +# + +session.session_close() diff --git a/qpid/python/examples/pubsub/topic_consumer.py b/qpid/python/examples/pubsub/topic_consumer.py deleted file mode 100644 index afe8bba91e..0000000000 --- a/qpid/python/examples/pubsub/topic_consumer.py +++ /dev/null @@ -1,118 +0,0 @@ -#!/usr/bin/env python -""" - topic_consumer.py - - This AMQP client reads all messages from the - "news", "weather", "usa", and "europe" queues - created and bound by config_topic_exchange.py. -""" - -import base64 - -import qpid -from qpid.client import Client -from qpid.content import Content -from qpid.queue import Empty - -#----- Functions ------------------------------------------- - -def dump_queue(client, queue_name): - - print "Messages queue: " + queue_name - - consumer_tag = queue_name # Use the queue name as the consumer tag - need a unique tag - queue = client.queue(consumer_tag) - - # Call basic_consume() to tell the broker to deliver messages - # from the AMQP queue to a local client queue. The broker will - # start delivering messages as soon as basic_consume() is called. - - session.message_subscribe(queue=queue_name, destination=consumer_tag) - session.message_flow(consumer_tag, 0, 0xFFFFFFFF) - session.message_flow(consumer_tag, 1, 0xFFFFFFFF) - - content = "" # Content of the last message read - final = "That's all, folks!" # In a message body, signals the last message - message = 0 - - while content != final: - try: - message = queue.get() - content = message.content.body - print content - except Empty: - if message != 0: - message.complete(cumulative=True) - print "No more messages!" - return - - - # Messages are not removed from the queue until they - # are acknowledged. Using multiple=True, all messages - # in the channel up to and including the one identified - # by the delivery tag are acknowledged. This is more efficient, - # because there are fewer network round-trips. - - if message != 0: - message.complete(cumulative=True) - - -#----- 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_info = session.session_open() -session_id = session_info.session_id - -#----- Main Body -- ---------------------------------------- - - -news = "news" + base64.urlsafe_b64encode(session_id) -weather = "weather" + base64.urlsafe_b64encode(session_id) -usa = "usa" + base64.urlsafe_b64encode(session_id) -europe = "europe" + base64.urlsafe_b64encode(session_id) - -session.queue_declare(queue=news, exclusive=True) -session.queue_declare(queue=weather, exclusive=True) -session.queue_declare(queue=usa, exclusive=True) -session.queue_declare(queue=europe, exclusive=True) - -# Routing keys may be "usa.news", "usa.weather", "europe.news", or "europe.weather". - -# The '#' symbol matches one component of a multipart name, e.g. "#.news" matches -# "europe.news" or "usa.news". - -session.queue_bind(exchange="amq.topic", queue=news, routing_key="#.news") -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.#") - -# Remind the user to start the topic producer - -print "Queues create - please start the topic producer" - -# Call dump_queue to print messages from each queue - -dump_queue(client, news) -dump_queue(client, weather) -dump_queue(client, usa) -dump_queue(client, europe) - -#----- Cleanup ------------------------------------------------ - -# Clean up before exiting so there are no open threads. - -session.session_close() diff --git a/qpid/python/examples/pubsub/topic_listener.py b/qpid/python/examples/pubsub/topic_listener.py new file mode 100644 index 0000000000..afe8bba91e --- /dev/null +++ b/qpid/python/examples/pubsub/topic_listener.py @@ -0,0 +1,118 @@ +#!/usr/bin/env python +""" + topic_consumer.py + + This AMQP client reads all messages from the + "news", "weather", "usa", and "europe" queues + created and bound by config_topic_exchange.py. +""" + +import base64 + +import qpid +from qpid.client import Client +from qpid.content import Content +from qpid.queue import Empty + +#----- Functions ------------------------------------------- + +def dump_queue(client, queue_name): + + print "Messages queue: " + queue_name + + consumer_tag = queue_name # Use the queue name as the consumer tag - need a unique tag + queue = client.queue(consumer_tag) + + # Call basic_consume() to tell the broker to deliver messages + # from the AMQP queue to a local client queue. The broker will + # start delivering messages as soon as basic_consume() is called. + + session.message_subscribe(queue=queue_name, destination=consumer_tag) + session.message_flow(consumer_tag, 0, 0xFFFFFFFF) + session.message_flow(consumer_tag, 1, 0xFFFFFFFF) + + content = "" # Content of the last message read + final = "That's all, folks!" # In a message body, signals the last message + message = 0 + + while content != final: + try: + message = queue.get() + content = message.content.body + print content + except Empty: + if message != 0: + message.complete(cumulative=True) + print "No more messages!" + return + + + # Messages are not removed from the queue until they + # are acknowledged. Using multiple=True, all messages + # in the channel up to and including the one identified + # by the delivery tag are acknowledged. This is more efficient, + # because there are fewer network round-trips. + + if message != 0: + message.complete(cumulative=True) + + +#----- 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_info = session.session_open() +session_id = session_info.session_id + +#----- Main Body -- ---------------------------------------- + + +news = "news" + base64.urlsafe_b64encode(session_id) +weather = "weather" + base64.urlsafe_b64encode(session_id) +usa = "usa" + base64.urlsafe_b64encode(session_id) +europe = "europe" + base64.urlsafe_b64encode(session_id) + +session.queue_declare(queue=news, exclusive=True) +session.queue_declare(queue=weather, exclusive=True) +session.queue_declare(queue=usa, exclusive=True) +session.queue_declare(queue=europe, exclusive=True) + +# Routing keys may be "usa.news", "usa.weather", "europe.news", or "europe.weather". + +# The '#' symbol matches one component of a multipart name, e.g. "#.news" matches +# "europe.news" or "usa.news". + +session.queue_bind(exchange="amq.topic", queue=news, routing_key="#.news") +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.#") + +# Remind the user to start the topic producer + +print "Queues create - please start the topic producer" + +# Call dump_queue to print messages from each queue + +dump_queue(client, news) +dump_queue(client, weather) +dump_queue(client, usa) +dump_queue(client, europe) + +#----- Cleanup ------------------------------------------------ + +# Clean up before exiting so there are no open threads. + +session.session_close() diff --git a/qpid/python/examples/pubsub/topic_producer.py b/qpid/python/examples/pubsub/topic_producer.py deleted file mode 100644 index c3b13cd82c..0000000000 --- a/qpid/python/examples/pubsub/topic_producer.py +++ /dev/null @@ -1,96 +0,0 @@ -#!/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() diff --git a/qpid/python/examples/pubsub/topic_publisher.py b/qpid/python/examples/pubsub/topic_publisher.py new file mode 100644 index 0000000000..c3b13cd82c --- /dev/null +++ b/qpid/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() -- cgit v1.2.1 From 8896a1a5ce01157036cc3096fdb33e8be50d4a02 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Wed, 5 Dec 2007 18:53:36 +0000 Subject: Reversed renaming git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@601467 13f79535-47bb-0310-9956-ffa450edef68 --- .../examples/direct/config_direct_exchange.py | 53 +++++++++ .../python/examples/direct/direct_config_queues.py | 53 --------- qpid/python/examples/direct/direct_consumer.py | 75 +++++++++++++ qpid/python/examples/direct/direct_producer.py | 51 +++++++++ qpid/python/examples/direct/direct_publisher.py | 51 --------- qpid/python/examples/direct/listener.py | 75 ------------- .../examples/fanout/config_fanout_exchange.py | 54 ++++++++++ .../python/examples/fanout/fanout_config_queues.py | 54 ---------- qpid/python/examples/fanout/fanout_consumer.py | 75 +++++++++++++ qpid/python/examples/fanout/fanout_producer.py | 48 +++++++++ qpid/python/examples/fanout/fanout_publisher.py | 48 --------- qpid/python/examples/fanout/listener.py | 75 ------------- qpid/python/examples/pubsub/topic_consumer.py | 118 +++++++++++++++++++++ qpid/python/examples/pubsub/topic_listener.py | 118 --------------------- qpid/python/examples/pubsub/topic_producer.py | 96 +++++++++++++++++ qpid/python/examples/pubsub/topic_publisher.py | 96 ----------------- 16 files changed, 570 insertions(+), 570 deletions(-) create mode 100644 qpid/python/examples/direct/config_direct_exchange.py delete mode 100644 qpid/python/examples/direct/direct_config_queues.py create mode 100644 qpid/python/examples/direct/direct_consumer.py create mode 100644 qpid/python/examples/direct/direct_producer.py delete mode 100644 qpid/python/examples/direct/direct_publisher.py delete mode 100644 qpid/python/examples/direct/listener.py create mode 100644 qpid/python/examples/fanout/config_fanout_exchange.py delete mode 100644 qpid/python/examples/fanout/fanout_config_queues.py create mode 100644 qpid/python/examples/fanout/fanout_consumer.py create mode 100644 qpid/python/examples/fanout/fanout_producer.py delete mode 100644 qpid/python/examples/fanout/fanout_publisher.py delete mode 100644 qpid/python/examples/fanout/listener.py create mode 100644 qpid/python/examples/pubsub/topic_consumer.py delete mode 100644 qpid/python/examples/pubsub/topic_listener.py create mode 100644 qpid/python/examples/pubsub/topic_producer.py delete mode 100644 qpid/python/examples/pubsub/topic_publisher.py (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/direct/config_direct_exchange.py b/qpid/python/examples/direct/config_direct_exchange.py new file mode 100644 index 0000000000..e64ad678b8 --- /dev/null +++ b/qpid/python/examples/direct/config_direct_exchange.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +""" + config_direct_exchange.py + + Creates and binds a queue on an AMQP direct exchange. + + All messages using the routing key "routing_key" are + sent to the queue named "message_queue". +""" + +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. + +client = Client(host, port, qpid.spec.load(amqp_spec)) +client.start({"LOGIN": user, "PASSWORD": password}) + +session = client.session() +session.session_open() + +#----- Create a queue ------------------------------------- + +# Create a queue named "listener" on channel 1, and bind it +# to the "amq.direct" exchange. +# +# queue_declare() creates an AMQP queue, which is held +# on the broker. Published messages are sent to the AMQP queue, +# from which messages are delivered to consumers. +# +# queue_bind() determines which messages are routed to a queue. +# Route all messages with the routing key "routing_key" to +# the AMQP queue named "message_queue". + +session.queue_declare(queue="message_queue") +session.queue_bind(exchange="amq.direct", queue="message_queue", routing_key="routing_key") + +#----- Cleanup --------------------------------------------- + +session.session_close() + diff --git a/qpid/python/examples/direct/direct_config_queues.py b/qpid/python/examples/direct/direct_config_queues.py deleted file mode 100644 index e64ad678b8..0000000000 --- a/qpid/python/examples/direct/direct_config_queues.py +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env python -""" - config_direct_exchange.py - - Creates and binds a queue on an AMQP direct exchange. - - All messages using the routing key "routing_key" are - sent to the queue named "message_queue". -""" - -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. - -client = Client(host, port, qpid.spec.load(amqp_spec)) -client.start({"LOGIN": user, "PASSWORD": password}) - -session = client.session() -session.session_open() - -#----- Create a queue ------------------------------------- - -# Create a queue named "listener" on channel 1, and bind it -# to the "amq.direct" exchange. -# -# queue_declare() creates an AMQP queue, which is held -# on the broker. Published messages are sent to the AMQP queue, -# from which messages are delivered to consumers. -# -# queue_bind() determines which messages are routed to a queue. -# Route all messages with the routing key "routing_key" to -# the AMQP queue named "message_queue". - -session.queue_declare(queue="message_queue") -session.queue_bind(exchange="amq.direct", queue="message_queue", routing_key="routing_key") - -#----- Cleanup --------------------------------------------- - -session.session_close() - diff --git a/qpid/python/examples/direct/direct_consumer.py b/qpid/python/examples/direct/direct_consumer.py new file mode 100644 index 0000000000..38b1ba30a0 --- /dev/null +++ b/qpid/python/examples/direct/direct_consumer.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +""" + direct_consumer.py + + This AMQP client reads messages from a message + queue named "message_queue". +""" + +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. + +client = Client(host, port, qpid.spec.load(amqp_spec)) +client.start({"LOGIN": user, "PASSWORD": password}) + +session = client.session() +session.session_open() + +#----- Read from queue -------------------------------------------- + +# Now let's create a local client queue and tell it to read +# incoming messages. + +# The consumer tag identifies the client-side queue. + +consumer_tag = "consumer1" +queue = client.queue(consumer_tag) + +# Call message_consume() to tell the broker to deliver messages +# from the AMQP queue to this local client queue. The broker will +# start delivering messages as soon as message_consume() is called. + +session.message_subscribe(queue="message_queue", destination=consumer_tag) +session.message_flow(consumer_tag, 0, 0xFFFFFFFF) # Kill these? +session.message_flow(consumer_tag, 1, 0xFFFFFFFF) # Kill these? + +# Initialize 'final' and 'content', variables used to identify the last message. + +final = "That's all, folks!" # In a message body, signals the last message +content = "" # Content of the last message read + +message = None +while content != final: + message = queue.get(timeout=10) + content = message.content.body + print content + +# Messages are not removed from the queue until they are +# acknowledged. Using cumulative=True, all messages from the session +# up to and including the one identified by the delivery tag are +# acknowledged. This is more efficient, because there are fewer +# network round-trips. + +message.complete(cumulative=True) + +#----- Cleanup ------------------------------------------------ + +# Clean up before exiting so there are no open threads. +# + +session.session_close() diff --git a/qpid/python/examples/direct/direct_producer.py b/qpid/python/examples/direct/direct_producer.py new file mode 100644 index 0000000000..6770e56803 --- /dev/null +++ b/qpid/python/examples/direct/direct_producer.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +""" + direct_producer.py + + Publishes messages to an AMQP direct exchange, using + the routing key "routing_key" +""" + +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. + +client = Client(host, port, qpid.spec.load(amqp_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. + +for i in range(10): + message = Content("message " + str(i)) + message["routing_key"] = "routing_key" + session.message_transfer(destination="amq.direct", content=message) + +final="That's all, folks!" +message = Content(final) +message["routing_key"] = "routing_key" +session.message_transfer(destination="amq.direct", content=message) + +#----- Cleanup -------------------------------------------- + +# Clean up before exiting so there are no open threads. + +session.session_close() + diff --git a/qpid/python/examples/direct/direct_publisher.py b/qpid/python/examples/direct/direct_publisher.py deleted file mode 100644 index 6770e56803..0000000000 --- a/qpid/python/examples/direct/direct_publisher.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env python -""" - direct_producer.py - - Publishes messages to an AMQP direct exchange, using - the routing key "routing_key" -""" - -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. - -client = Client(host, port, qpid.spec.load(amqp_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. - -for i in range(10): - message = Content("message " + str(i)) - message["routing_key"] = "routing_key" - session.message_transfer(destination="amq.direct", content=message) - -final="That's all, folks!" -message = Content(final) -message["routing_key"] = "routing_key" -session.message_transfer(destination="amq.direct", content=message) - -#----- Cleanup -------------------------------------------- - -# Clean up before exiting so there are no open threads. - -session.session_close() - diff --git a/qpid/python/examples/direct/listener.py b/qpid/python/examples/direct/listener.py deleted file mode 100644 index 38b1ba30a0..0000000000 --- a/qpid/python/examples/direct/listener.py +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env python -""" - direct_consumer.py - - This AMQP client reads messages from a message - queue named "message_queue". -""" - -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. - -client = Client(host, port, qpid.spec.load(amqp_spec)) -client.start({"LOGIN": user, "PASSWORD": password}) - -session = client.session() -session.session_open() - -#----- Read from queue -------------------------------------------- - -# Now let's create a local client queue and tell it to read -# incoming messages. - -# The consumer tag identifies the client-side queue. - -consumer_tag = "consumer1" -queue = client.queue(consumer_tag) - -# Call message_consume() to tell the broker to deliver messages -# from the AMQP queue to this local client queue. The broker will -# start delivering messages as soon as message_consume() is called. - -session.message_subscribe(queue="message_queue", destination=consumer_tag) -session.message_flow(consumer_tag, 0, 0xFFFFFFFF) # Kill these? -session.message_flow(consumer_tag, 1, 0xFFFFFFFF) # Kill these? - -# Initialize 'final' and 'content', variables used to identify the last message. - -final = "That's all, folks!" # In a message body, signals the last message -content = "" # Content of the last message read - -message = None -while content != final: - message = queue.get(timeout=10) - content = message.content.body - print content - -# Messages are not removed from the queue until they are -# acknowledged. Using cumulative=True, all messages from the session -# up to and including the one identified by the delivery tag are -# acknowledged. This is more efficient, because there are fewer -# network round-trips. - -message.complete(cumulative=True) - -#----- Cleanup ------------------------------------------------ - -# Clean up before exiting so there are no open threads. -# - -session.session_close() diff --git a/qpid/python/examples/fanout/config_fanout_exchange.py b/qpid/python/examples/fanout/config_fanout_exchange.py new file mode 100644 index 0000000000..3315f5bc14 --- /dev/null +++ b/qpid/python/examples/fanout/config_fanout_exchange.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python +""" + config_direct_exchange.py + + Creates and binds a queue on an AMQP direct exchange. + + All messages using the routing key "routing_key" are + sent to the queue named "message_queue". +""" + +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. + +client = Client(host, port, qpid.spec.load(amqp_spec)) +client.start({"LOGIN": user, "PASSWORD": password}) + +session = client.session() +session.session_open() + +#----- Create a queue ------------------------------------- + +# Create a queue named "listener" on channel 1, and bind it +# to the "amq.fanout" exchange. +# +# queue_declare() creates an AMQP queue, which is held +# on the broker. Published messages are sent to the AMQP queue, +# from which messages are delivered to consumers. +# +# queue_bind() determines which messages are routed to a queue. +# Route all messages with the routing key "routing_key" to +# the AMQP queue named "message_queue". + +session.queue_declare(queue="message_queue") +session.queue_bind(exchange="amq.fanout", queue="message_queue") + +#----- Cleanup --------------------------------------------- + +# Clean up before exiting so there are no open threads. + +session.session_close() diff --git a/qpid/python/examples/fanout/fanout_config_queues.py b/qpid/python/examples/fanout/fanout_config_queues.py deleted file mode 100644 index 3315f5bc14..0000000000 --- a/qpid/python/examples/fanout/fanout_config_queues.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python -""" - config_direct_exchange.py - - Creates and binds a queue on an AMQP direct exchange. - - All messages using the routing key "routing_key" are - sent to the queue named "message_queue". -""" - -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. - -client = Client(host, port, qpid.spec.load(amqp_spec)) -client.start({"LOGIN": user, "PASSWORD": password}) - -session = client.session() -session.session_open() - -#----- Create a queue ------------------------------------- - -# Create a queue named "listener" on channel 1, and bind it -# to the "amq.fanout" exchange. -# -# queue_declare() creates an AMQP queue, which is held -# on the broker. Published messages are sent to the AMQP queue, -# from which messages are delivered to consumers. -# -# queue_bind() determines which messages are routed to a queue. -# Route all messages with the routing key "routing_key" to -# the AMQP queue named "message_queue". - -session.queue_declare(queue="message_queue") -session.queue_bind(exchange="amq.fanout", queue="message_queue") - -#----- Cleanup --------------------------------------------- - -# Clean up before exiting so there are no open threads. - -session.session_close() diff --git a/qpid/python/examples/fanout/fanout_consumer.py b/qpid/python/examples/fanout/fanout_consumer.py new file mode 100644 index 0000000000..e9a2291f4c --- /dev/null +++ b/qpid/python/examples/fanout/fanout_consumer.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +""" + direct_consumer.py + + This AMQP client reads messages from a message + queue named "message_queue". +""" + +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. + +client = Client(host, port, qpid.spec.load(amqp_spec)) +client.start({"LOGIN": user, "PASSWORD": password}) + +session = client.session() +session.session_open() + +#----- Read from queue -------------------------------------------- + +# Now let's create a local client queue and tell it to read +# incoming messages. + +# The consumer tag identifies the client-side queue. + +consumer_tag = "consumer1" +queue = client.queue(consumer_tag) + +# Call message_consume() to tell the broker to deliver messages +# from the AMQP queue to this local client queue. The broker will +# start delivering messages as soon as message_consume() is called. + +session.message_subscribe(queue="message_queue", destination=consumer_tag) +session.message_flow(consumer_tag, 0, 0xFFFFFFFF) +session.message_flow(consumer_tag, 1, 0xFFFFFFFF) + +# Initialize 'final' and 'content', variables used to identify the last message. + +final = "That's all, folks!" # In a message body, signals the last message +content = "" # Content of the last message read + +message = None +while content != final: + message = queue.get(timeout=10) + content = message.content.body + print content + +# Messages are not removed from the queue until they are +# acknowledged. Using cumulative=True, all messages from the session +# up to and including the one identified by the delivery tag are +# acknowledged. This is more efficient, because there are fewer +# network round-trips. + +message.complete(cumulative=True) + +#----- Cleanup ------------------------------------------------ + +# Clean up before exiting so there are no open threads. +# + +session.session_close() diff --git a/qpid/python/examples/fanout/fanout_producer.py b/qpid/python/examples/fanout/fanout_producer.py new file mode 100644 index 0000000000..92ca7b7ec0 --- /dev/null +++ b/qpid/python/examples/fanout/fanout_producer.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python +""" + direct_producer.py + + Publishes messages to an AMQP direct exchange, using + the routing key "routing_key" +""" + +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. + +client = Client(host, port, qpid.spec.load(amqp_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. + +for i in range(10): + message = Content(body="message " + str(i)) + session.message_transfer(destination="amq.fanout", content=message) + +final="That's all, folks!" +message=Content(final) +session.message_transfer(destination="amq.fanout", content=message) + +#----- Cleanup -------------------------------------------- + +# Clean up before exiting so there are no open threads. + +session.session_close() diff --git a/qpid/python/examples/fanout/fanout_publisher.py b/qpid/python/examples/fanout/fanout_publisher.py deleted file mode 100644 index 92ca7b7ec0..0000000000 --- a/qpid/python/examples/fanout/fanout_publisher.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python -""" - direct_producer.py - - Publishes messages to an AMQP direct exchange, using - the routing key "routing_key" -""" - -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. - -client = Client(host, port, qpid.spec.load(amqp_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. - -for i in range(10): - message = Content(body="message " + str(i)) - session.message_transfer(destination="amq.fanout", content=message) - -final="That's all, folks!" -message=Content(final) -session.message_transfer(destination="amq.fanout", content=message) - -#----- Cleanup -------------------------------------------- - -# Clean up before exiting so there are no open threads. - -session.session_close() diff --git a/qpid/python/examples/fanout/listener.py b/qpid/python/examples/fanout/listener.py deleted file mode 100644 index e9a2291f4c..0000000000 --- a/qpid/python/examples/fanout/listener.py +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env python -""" - direct_consumer.py - - This AMQP client reads messages from a message - queue named "message_queue". -""" - -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. - -client = Client(host, port, qpid.spec.load(amqp_spec)) -client.start({"LOGIN": user, "PASSWORD": password}) - -session = client.session() -session.session_open() - -#----- Read from queue -------------------------------------------- - -# Now let's create a local client queue and tell it to read -# incoming messages. - -# The consumer tag identifies the client-side queue. - -consumer_tag = "consumer1" -queue = client.queue(consumer_tag) - -# Call message_consume() to tell the broker to deliver messages -# from the AMQP queue to this local client queue. The broker will -# start delivering messages as soon as message_consume() is called. - -session.message_subscribe(queue="message_queue", destination=consumer_tag) -session.message_flow(consumer_tag, 0, 0xFFFFFFFF) -session.message_flow(consumer_tag, 1, 0xFFFFFFFF) - -# Initialize 'final' and 'content', variables used to identify the last message. - -final = "That's all, folks!" # In a message body, signals the last message -content = "" # Content of the last message read - -message = None -while content != final: - message = queue.get(timeout=10) - content = message.content.body - print content - -# Messages are not removed from the queue until they are -# acknowledged. Using cumulative=True, all messages from the session -# up to and including the one identified by the delivery tag are -# acknowledged. This is more efficient, because there are fewer -# network round-trips. - -message.complete(cumulative=True) - -#----- Cleanup ------------------------------------------------ - -# Clean up before exiting so there are no open threads. -# - -session.session_close() diff --git a/qpid/python/examples/pubsub/topic_consumer.py b/qpid/python/examples/pubsub/topic_consumer.py new file mode 100644 index 0000000000..afe8bba91e --- /dev/null +++ b/qpid/python/examples/pubsub/topic_consumer.py @@ -0,0 +1,118 @@ +#!/usr/bin/env python +""" + topic_consumer.py + + This AMQP client reads all messages from the + "news", "weather", "usa", and "europe" queues + created and bound by config_topic_exchange.py. +""" + +import base64 + +import qpid +from qpid.client import Client +from qpid.content import Content +from qpid.queue import Empty + +#----- Functions ------------------------------------------- + +def dump_queue(client, queue_name): + + print "Messages queue: " + queue_name + + consumer_tag = queue_name # Use the queue name as the consumer tag - need a unique tag + queue = client.queue(consumer_tag) + + # Call basic_consume() to tell the broker to deliver messages + # from the AMQP queue to a local client queue. The broker will + # start delivering messages as soon as basic_consume() is called. + + session.message_subscribe(queue=queue_name, destination=consumer_tag) + session.message_flow(consumer_tag, 0, 0xFFFFFFFF) + session.message_flow(consumer_tag, 1, 0xFFFFFFFF) + + content = "" # Content of the last message read + final = "That's all, folks!" # In a message body, signals the last message + message = 0 + + while content != final: + try: + message = queue.get() + content = message.content.body + print content + except Empty: + if message != 0: + message.complete(cumulative=True) + print "No more messages!" + return + + + # Messages are not removed from the queue until they + # are acknowledged. Using multiple=True, all messages + # in the channel up to and including the one identified + # by the delivery tag are acknowledged. This is more efficient, + # because there are fewer network round-trips. + + if message != 0: + message.complete(cumulative=True) + + +#----- 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_info = session.session_open() +session_id = session_info.session_id + +#----- Main Body -- ---------------------------------------- + + +news = "news" + base64.urlsafe_b64encode(session_id) +weather = "weather" + base64.urlsafe_b64encode(session_id) +usa = "usa" + base64.urlsafe_b64encode(session_id) +europe = "europe" + base64.urlsafe_b64encode(session_id) + +session.queue_declare(queue=news, exclusive=True) +session.queue_declare(queue=weather, exclusive=True) +session.queue_declare(queue=usa, exclusive=True) +session.queue_declare(queue=europe, exclusive=True) + +# Routing keys may be "usa.news", "usa.weather", "europe.news", or "europe.weather". + +# The '#' symbol matches one component of a multipart name, e.g. "#.news" matches +# "europe.news" or "usa.news". + +session.queue_bind(exchange="amq.topic", queue=news, routing_key="#.news") +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.#") + +# Remind the user to start the topic producer + +print "Queues create - please start the topic producer" + +# Call dump_queue to print messages from each queue + +dump_queue(client, news) +dump_queue(client, weather) +dump_queue(client, usa) +dump_queue(client, europe) + +#----- Cleanup ------------------------------------------------ + +# Clean up before exiting so there are no open threads. + +session.session_close() diff --git a/qpid/python/examples/pubsub/topic_listener.py b/qpid/python/examples/pubsub/topic_listener.py deleted file mode 100644 index afe8bba91e..0000000000 --- a/qpid/python/examples/pubsub/topic_listener.py +++ /dev/null @@ -1,118 +0,0 @@ -#!/usr/bin/env python -""" - topic_consumer.py - - This AMQP client reads all messages from the - "news", "weather", "usa", and "europe" queues - created and bound by config_topic_exchange.py. -""" - -import base64 - -import qpid -from qpid.client import Client -from qpid.content import Content -from qpid.queue import Empty - -#----- Functions ------------------------------------------- - -def dump_queue(client, queue_name): - - print "Messages queue: " + queue_name - - consumer_tag = queue_name # Use the queue name as the consumer tag - need a unique tag - queue = client.queue(consumer_tag) - - # Call basic_consume() to tell the broker to deliver messages - # from the AMQP queue to a local client queue. The broker will - # start delivering messages as soon as basic_consume() is called. - - session.message_subscribe(queue=queue_name, destination=consumer_tag) - session.message_flow(consumer_tag, 0, 0xFFFFFFFF) - session.message_flow(consumer_tag, 1, 0xFFFFFFFF) - - content = "" # Content of the last message read - final = "That's all, folks!" # In a message body, signals the last message - message = 0 - - while content != final: - try: - message = queue.get() - content = message.content.body - print content - except Empty: - if message != 0: - message.complete(cumulative=True) - print "No more messages!" - return - - - # Messages are not removed from the queue until they - # are acknowledged. Using multiple=True, all messages - # in the channel up to and including the one identified - # by the delivery tag are acknowledged. This is more efficient, - # because there are fewer network round-trips. - - if message != 0: - message.complete(cumulative=True) - - -#----- 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_info = session.session_open() -session_id = session_info.session_id - -#----- Main Body -- ---------------------------------------- - - -news = "news" + base64.urlsafe_b64encode(session_id) -weather = "weather" + base64.urlsafe_b64encode(session_id) -usa = "usa" + base64.urlsafe_b64encode(session_id) -europe = "europe" + base64.urlsafe_b64encode(session_id) - -session.queue_declare(queue=news, exclusive=True) -session.queue_declare(queue=weather, exclusive=True) -session.queue_declare(queue=usa, exclusive=True) -session.queue_declare(queue=europe, exclusive=True) - -# Routing keys may be "usa.news", "usa.weather", "europe.news", or "europe.weather". - -# The '#' symbol matches one component of a multipart name, e.g. "#.news" matches -# "europe.news" or "usa.news". - -session.queue_bind(exchange="amq.topic", queue=news, routing_key="#.news") -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.#") - -# Remind the user to start the topic producer - -print "Queues create - please start the topic producer" - -# Call dump_queue to print messages from each queue - -dump_queue(client, news) -dump_queue(client, weather) -dump_queue(client, usa) -dump_queue(client, europe) - -#----- Cleanup ------------------------------------------------ - -# Clean up before exiting so there are no open threads. - -session.session_close() diff --git a/qpid/python/examples/pubsub/topic_producer.py b/qpid/python/examples/pubsub/topic_producer.py new file mode 100644 index 0000000000..c3b13cd82c --- /dev/null +++ b/qpid/python/examples/pubsub/topic_producer.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() diff --git a/qpid/python/examples/pubsub/topic_publisher.py b/qpid/python/examples/pubsub/topic_publisher.py deleted file mode 100644 index c3b13cd82c..0000000000 --- a/qpid/python/examples/pubsub/topic_publisher.py +++ /dev/null @@ -1,96 +0,0 @@ -#!/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() -- cgit v1.2.1 From a8cfd6ce0dd80f4e2980f48282d074aef53f8132 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Wed, 19 Dec 2007 16:01:28 +0000 Subject: 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 --- qpid/python/examples/pubsub/topic_consumer.py | 118 ---------------------- qpid/python/examples/pubsub/topic_producer.py | 96 ------------------ qpid/python/examples/pubsub/topic_publisher.py | 80 +++++++++++++++ qpid/python/examples/pubsub/topic_subscriber.py | 124 ++++++++++++++++++++++++ 4 files changed, 204 insertions(+), 214 deletions(-) delete mode 100644 qpid/python/examples/pubsub/topic_consumer.py delete mode 100644 qpid/python/examples/pubsub/topic_producer.py create mode 100644 qpid/python/examples/pubsub/topic_publisher.py create mode 100644 qpid/python/examples/pubsub/topic_subscriber.py (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/pubsub/topic_consumer.py b/qpid/python/examples/pubsub/topic_consumer.py deleted file mode 100644 index afe8bba91e..0000000000 --- a/qpid/python/examples/pubsub/topic_consumer.py +++ /dev/null @@ -1,118 +0,0 @@ -#!/usr/bin/env python -""" - topic_consumer.py - - This AMQP client reads all messages from the - "news", "weather", "usa", and "europe" queues - created and bound by config_topic_exchange.py. -""" - -import base64 - -import qpid -from qpid.client import Client -from qpid.content import Content -from qpid.queue import Empty - -#----- Functions ------------------------------------------- - -def dump_queue(client, queue_name): - - print "Messages queue: " + queue_name - - consumer_tag = queue_name # Use the queue name as the consumer tag - need a unique tag - queue = client.queue(consumer_tag) - - # Call basic_consume() to tell the broker to deliver messages - # from the AMQP queue to a local client queue. The broker will - # start delivering messages as soon as basic_consume() is called. - - session.message_subscribe(queue=queue_name, destination=consumer_tag) - session.message_flow(consumer_tag, 0, 0xFFFFFFFF) - session.message_flow(consumer_tag, 1, 0xFFFFFFFF) - - content = "" # Content of the last message read - final = "That's all, folks!" # In a message body, signals the last message - message = 0 - - while content != final: - try: - message = queue.get() - content = message.content.body - print content - except Empty: - if message != 0: - message.complete(cumulative=True) - print "No more messages!" - return - - - # Messages are not removed from the queue until they - # are acknowledged. Using multiple=True, all messages - # in the channel up to and including the one identified - # by the delivery tag are acknowledged. This is more efficient, - # because there are fewer network round-trips. - - if message != 0: - message.complete(cumulative=True) - - -#----- 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_info = session.session_open() -session_id = session_info.session_id - -#----- Main Body -- ---------------------------------------- - - -news = "news" + base64.urlsafe_b64encode(session_id) -weather = "weather" + base64.urlsafe_b64encode(session_id) -usa = "usa" + base64.urlsafe_b64encode(session_id) -europe = "europe" + base64.urlsafe_b64encode(session_id) - -session.queue_declare(queue=news, exclusive=True) -session.queue_declare(queue=weather, exclusive=True) -session.queue_declare(queue=usa, exclusive=True) -session.queue_declare(queue=europe, exclusive=True) - -# Routing keys may be "usa.news", "usa.weather", "europe.news", or "europe.weather". - -# The '#' symbol matches one component of a multipart name, e.g. "#.news" matches -# "europe.news" or "usa.news". - -session.queue_bind(exchange="amq.topic", queue=news, routing_key="#.news") -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.#") - -# Remind the user to start the topic producer - -print "Queues create - please start the topic producer" - -# Call dump_queue to print messages from each queue - -dump_queue(client, news) -dump_queue(client, weather) -dump_queue(client, usa) -dump_queue(client, europe) - -#----- Cleanup ------------------------------------------------ - -# Clean up before exiting so there are no open threads. - -session.session_close() diff --git a/qpid/python/examples/pubsub/topic_producer.py b/qpid/python/examples/pubsub/topic_producer.py deleted file mode 100644 index c3b13cd82c..0000000000 --- a/qpid/python/examples/pubsub/topic_producer.py +++ /dev/null @@ -1,96 +0,0 @@ -#!/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() 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() diff --git a/qpid/python/examples/pubsub/topic_subscriber.py b/qpid/python/examples/pubsub/topic_subscriber.py new file mode 100644 index 0000000000..08682f0674 --- /dev/null +++ b/qpid/python/examples/pubsub/topic_subscriber.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python +""" + topic_subscriber.py + + This subscriber creates private queues and binds them + to the topics "usa.#", "europe.#", "#.news", and "#.weather". +""" + +import base64 + +import qpid +from qpid.client import Client +from qpid.content import Content +from qpid.queue import Empty + +#----- Functions ------------------------------------------- + +def dump_queue(client, queue_name): + + print "Messages queue: " + queue_name + + consumer_tag = queue_name # Use the queue name as the consumer tag - need a unique tag + queue = client.queue(consumer_tag) + + # Call basic_consume() to tell the broker to deliver messages + # from the AMQP queue to a local client queue. The broker will + # start delivering messages as soon as basic_consume() is called. + + session.message_subscribe(queue=queue_name, destination=consumer_tag) + session.message_flow(consumer_tag, 0, 0xFFFFFFFF) + session.message_flow(consumer_tag, 1, 0xFFFFFFFF) + + content = "" # Content of the last message read + final = "That's all, folks!" # In a message body, signals the last message + message = 0 + + while content != final: + try: + message = queue.get() + content = message.content.body + print content + except Empty: + if message != 0: + message.complete(cumulative=True) + print "No more messages!" + return + + + # Messages are not removed from the queue until they + # are acknowledged. Using multiple=True, all messages + # in the channel up to and including the one identified + # by the delivery tag are acknowledged. This is more efficient, + # because there are fewer network round-trips. + + if message != 0: + message.complete(cumulative=True) + + +#----- 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_info = session.session_open() +session_id = session_info.session_id + +#----- Main Body -- ---------------------------------------- + + +news = "news" + base64.urlsafe_b64encode(session_id) +weather = "weather" + base64.urlsafe_b64encode(session_id) +usa = "usa" + base64.urlsafe_b64encode(session_id) +europe = "europe" + base64.urlsafe_b64encode(session_id) + +session.queue_declare(queue=news, exclusive=True) +session.queue_declare(queue=weather, exclusive=True) +session.queue_declare(queue=usa, exclusive=True) +session.queue_declare(queue=europe, exclusive=True) + +# Routing keys may be "usa.news", "usa.weather", "europe.news", or "europe.weather". + +# The '#' symbol matches one component of a multipart name, e.g. "#.news" matches +# "europe.news" or "usa.news". + +session.queue_bind(exchange="amq.topic", queue=news, routing_key="#.news") +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" + +# Call dump_queue to print messages from each queue + +dump_queue(client, news) +dump_queue(client, weather) +dump_queue(client, usa) +dump_queue(client, europe) + +#----- Cleanup ------------------------------------------------ + +# Clean up before exiting so there are no open threads. + +session.session_close() -- cgit v1.2.1 From a3f994526194bda58a1e160b3191eb944ec1f6dc Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Thu, 20 Dec 2007 16:40:12 +0000 Subject: Further renames as suggested by jrobie@redhat.com git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@605975 13f79535-47bb-0310-9956-ffa450edef68 --- .../examples/direct/config_direct_exchange.py | 53 ------------- qpid/python/examples/direct/declare_queues.py | 53 +++++++++++++ qpid/python/examples/direct/direct_producer.py | 1 - qpid/python/examples/direct/listener.py | 87 ++++++++++++++++++++++ .../examples/fanout/config_fanout_exchange.py | 54 -------------- qpid/python/examples/fanout/declare_queues.py | 54 ++++++++++++++ qpid/python/examples/fanout/listener.py | 86 +++++++++++++++++++++ 7 files changed, 280 insertions(+), 108 deletions(-) delete mode 100644 qpid/python/examples/direct/config_direct_exchange.py create mode 100644 qpid/python/examples/direct/declare_queues.py create mode 100644 qpid/python/examples/direct/listener.py delete mode 100644 qpid/python/examples/fanout/config_fanout_exchange.py create mode 100644 qpid/python/examples/fanout/declare_queues.py create mode 100644 qpid/python/examples/fanout/listener.py (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/direct/config_direct_exchange.py b/qpid/python/examples/direct/config_direct_exchange.py deleted file mode 100644 index e64ad678b8..0000000000 --- a/qpid/python/examples/direct/config_direct_exchange.py +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env python -""" - config_direct_exchange.py - - Creates and binds a queue on an AMQP direct exchange. - - All messages using the routing key "routing_key" are - sent to the queue named "message_queue". -""" - -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. - -client = Client(host, port, qpid.spec.load(amqp_spec)) -client.start({"LOGIN": user, "PASSWORD": password}) - -session = client.session() -session.session_open() - -#----- Create a queue ------------------------------------- - -# Create a queue named "listener" on channel 1, and bind it -# to the "amq.direct" exchange. -# -# queue_declare() creates an AMQP queue, which is held -# on the broker. Published messages are sent to the AMQP queue, -# from which messages are delivered to consumers. -# -# queue_bind() determines which messages are routed to a queue. -# Route all messages with the routing key "routing_key" to -# the AMQP queue named "message_queue". - -session.queue_declare(queue="message_queue") -session.queue_bind(exchange="amq.direct", queue="message_queue", routing_key="routing_key") - -#----- Cleanup --------------------------------------------- - -session.session_close() - diff --git a/qpid/python/examples/direct/declare_queues.py b/qpid/python/examples/direct/declare_queues.py new file mode 100644 index 0000000000..e64ad678b8 --- /dev/null +++ b/qpid/python/examples/direct/declare_queues.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +""" + config_direct_exchange.py + + Creates and binds a queue on an AMQP direct exchange. + + All messages using the routing key "routing_key" are + sent to the queue named "message_queue". +""" + +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. + +client = Client(host, port, qpid.spec.load(amqp_spec)) +client.start({"LOGIN": user, "PASSWORD": password}) + +session = client.session() +session.session_open() + +#----- Create a queue ------------------------------------- + +# Create a queue named "listener" on channel 1, and bind it +# to the "amq.direct" exchange. +# +# queue_declare() creates an AMQP queue, which is held +# on the broker. Published messages are sent to the AMQP queue, +# from which messages are delivered to consumers. +# +# queue_bind() determines which messages are routed to a queue. +# Route all messages with the routing key "routing_key" to +# the AMQP queue named "message_queue". + +session.queue_declare(queue="message_queue") +session.queue_bind(exchange="amq.direct", queue="message_queue", routing_key="routing_key") + +#----- Cleanup --------------------------------------------- + +session.session_close() + diff --git a/qpid/python/examples/direct/direct_producer.py b/qpid/python/examples/direct/direct_producer.py index 6770e56803..ff662477ce 100644 --- a/qpid/python/examples/direct/direct_producer.py +++ b/qpid/python/examples/direct/direct_producer.py @@ -48,4 +48,3 @@ session.message_transfer(destination="amq.direct", content=message) # Clean up before exiting so there are no open threads. session.session_close() - diff --git a/qpid/python/examples/direct/listener.py b/qpid/python/examples/direct/listener.py new file mode 100644 index 0000000000..e5eee72637 --- /dev/null +++ b/qpid/python/examples/direct/listener.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python +""" + listener.py + + This AMQP client reads messages from a message + queue named "message_queue". It is implemented + as a message listener. +""" + +import qpid +from qpid.client import Client +from qpid.content import Content +from qpid.queue import Empty +from time import sleep + + +#----- Message Receive Handler ----------------------------- +class Receiver: + def __init__ (self): + self.finalReceived = False + + def isFinal (self): + return self.finalReceived + + def Handler (self, message): + content = message.content.body + print content + if content == "That's all, folks!": + self.finalReceived = True + + # Messages are not removed from the queue until they are + # acknowledged. Using cumulative=True, all messages from the session + # up to and including the one identified by the delivery tag are + # acknowledged. This is more efficient, because there are fewer + # network round-trips. + message.complete(cumulative=True) + + +#----- 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. + +client = Client(host, port, qpid.spec.load(amqp_spec)) +client.start({"LOGIN": user, "PASSWORD": password}) + +session = client.session() +session.session_open() + +#----- Read from queue -------------------------------------------- + +# Now let's create a local client queue and tell it to read +# incoming messages. + +# The consumer tag identifies the client-side queue. + +consumer_tag = "consumer1" +queue = client.queue(consumer_tag) + +# Call message_consume() to tell the broker to deliver messages +# from the AMQP queue to this local client queue. The broker will +# start delivering messages as soon as message_consume() is called. + +session.message_subscribe(queue="message_queue", destination=consumer_tag) +session.message_flow(consumer_tag, 0, 0xFFFFFFFF) # Kill these? +session.message_flow(consumer_tag, 1, 0xFFFFFFFF) # Kill these? + +receiver = Receiver () +queue.listen (receiver.Handler) + +while not receiver.isFinal (): + sleep (1) + + +#----- Cleanup ------------------------------------------------ + +# Clean up before exiting so there are no open threads. +# + +session.session_close() diff --git a/qpid/python/examples/fanout/config_fanout_exchange.py b/qpid/python/examples/fanout/config_fanout_exchange.py deleted file mode 100644 index 3315f5bc14..0000000000 --- a/qpid/python/examples/fanout/config_fanout_exchange.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python -""" - config_direct_exchange.py - - Creates and binds a queue on an AMQP direct exchange. - - All messages using the routing key "routing_key" are - sent to the queue named "message_queue". -""" - -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. - -client = Client(host, port, qpid.spec.load(amqp_spec)) -client.start({"LOGIN": user, "PASSWORD": password}) - -session = client.session() -session.session_open() - -#----- Create a queue ------------------------------------- - -# Create a queue named "listener" on channel 1, and bind it -# to the "amq.fanout" exchange. -# -# queue_declare() creates an AMQP queue, which is held -# on the broker. Published messages are sent to the AMQP queue, -# from which messages are delivered to consumers. -# -# queue_bind() determines which messages are routed to a queue. -# Route all messages with the routing key "routing_key" to -# the AMQP queue named "message_queue". - -session.queue_declare(queue="message_queue") -session.queue_bind(exchange="amq.fanout", queue="message_queue") - -#----- Cleanup --------------------------------------------- - -# Clean up before exiting so there are no open threads. - -session.session_close() diff --git a/qpid/python/examples/fanout/declare_queues.py b/qpid/python/examples/fanout/declare_queues.py new file mode 100644 index 0000000000..3315f5bc14 --- /dev/null +++ b/qpid/python/examples/fanout/declare_queues.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python +""" + config_direct_exchange.py + + Creates and binds a queue on an AMQP direct exchange. + + All messages using the routing key "routing_key" are + sent to the queue named "message_queue". +""" + +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. + +client = Client(host, port, qpid.spec.load(amqp_spec)) +client.start({"LOGIN": user, "PASSWORD": password}) + +session = client.session() +session.session_open() + +#----- Create a queue ------------------------------------- + +# Create a queue named "listener" on channel 1, and bind it +# to the "amq.fanout" exchange. +# +# queue_declare() creates an AMQP queue, which is held +# on the broker. Published messages are sent to the AMQP queue, +# from which messages are delivered to consumers. +# +# queue_bind() determines which messages are routed to a queue. +# Route all messages with the routing key "routing_key" to +# the AMQP queue named "message_queue". + +session.queue_declare(queue="message_queue") +session.queue_bind(exchange="amq.fanout", queue="message_queue") + +#----- Cleanup --------------------------------------------- + +# Clean up before exiting so there are no open threads. + +session.session_close() diff --git a/qpid/python/examples/fanout/listener.py b/qpid/python/examples/fanout/listener.py new file mode 100644 index 0000000000..4779466fd9 --- /dev/null +++ b/qpid/python/examples/fanout/listener.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python +""" + direct_consumer.py + + This AMQP client reads messages from a message + queue named "message_queue". +""" + +import qpid +from qpid.client import Client +from qpid.content import Content +from qpid.queue import Empty +from time import sleep + + +#----- Message Receive Handler ----------------------------- +class Receiver: + def __init__ (self): + self.finalReceived = False + + def isFinal (self): + return self.finalReceived + + def Handler (self, message): + content = message.content.body + print content + if content == "That's all, folks!": + self.finalReceived = True + + # Messages are not removed from the queue until they are + # acknowledged. Using cumulative=True, all messages from the session + # up to and including the one identified by the delivery tag are + # acknowledged. This is more efficient, because there are fewer + # network round-trips. + message.complete(cumulative=True) + + +#----- 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. + +client = Client(host, port, qpid.spec.load(amqp_spec)) +client.start({"LOGIN": user, "PASSWORD": password}) + +session = client.session() +session.session_open() + +#----- Read from queue -------------------------------------------- + +# Now let's create a local client queue and tell it to read +# incoming messages. + +# The consumer tag identifies the client-side queue. + +consumer_tag = "consumer1" +queue = client.queue(consumer_tag) + +# Call message_consume() to tell the broker to deliver messages +# from the AMQP queue to this local client queue. The broker will +# start delivering messages as soon as message_consume() is called. + +session.message_subscribe(queue="message_queue", destination=consumer_tag) +session.message_flow(consumer_tag, 0, 0xFFFFFFFF) # Kill these? +session.message_flow(consumer_tag, 1, 0xFFFFFFFF) # Kill these? + +receiver = Receiver () +queue.listen (receiver.Handler) + +while not receiver.isFinal (): + sleep (1) + + +#----- Cleanup ------------------------------------------------ + +# Clean up before exiting so there are no open threads. +# + +session.session_close() -- cgit v1.2.1 From 70f2437cc12aa48958a0ff3f7a1d59ce29a5eb47 Mon Sep 17 00:00:00 2001 From: Arnaud Simon Date: Fri, 18 Jan 2008 10:36:50 +0000 Subject: Qpid-745 git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@613126 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/direct/declare_queues.py | 6 ++---- qpid/python/examples/direct/listener.py | 4 ++-- qpid/python/examples/fanout/declare_queues.py | 5 +---- qpid/python/examples/fanout/fanout_consumer.py | 6 +++--- qpid/python/examples/fanout/fanout_producer.py | 2 +- qpid/python/examples/fanout/listener.py | 6 +++--- qpid/python/examples/pubsub/topic_subscriber.py | 4 ++-- qpid/python/examples/request-response/client.py | 2 +- qpid/python/examples/request-response/server.py | 2 +- 9 files changed, 16 insertions(+), 21 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/direct/declare_queues.py b/qpid/python/examples/direct/declare_queues.py index e64ad678b8..0160f66a1d 100644 --- a/qpid/python/examples/direct/declare_queues.py +++ b/qpid/python/examples/direct/declare_queues.py @@ -1,6 +1,6 @@ #!/usr/bin/env python """ - config_direct_exchange.py + declare_queues.py Creates and binds a queue on an AMQP direct exchange. @@ -33,9 +33,6 @@ session.session_open() #----- Create a queue ------------------------------------- -# Create a queue named "listener" on channel 1, and bind it -# to the "amq.direct" exchange. -# # queue_declare() creates an AMQP queue, which is held # on the broker. Published messages are sent to the AMQP queue, # from which messages are delivered to consumers. @@ -51,3 +48,4 @@ session.queue_bind(exchange="amq.direct", queue="message_queue", routing_key="ro session.session_close() + diff --git a/qpid/python/examples/direct/listener.py b/qpid/python/examples/direct/listener.py index e5eee72637..8324cc76a6 100644 --- a/qpid/python/examples/direct/listener.py +++ b/qpid/python/examples/direct/listener.py @@ -64,9 +64,9 @@ session.session_open() consumer_tag = "consumer1" queue = client.queue(consumer_tag) -# Call message_consume() to tell the broker to deliver messages +# Call message_subscribe() to tell the broker to deliver messages # from the AMQP queue to this local client queue. The broker will -# start delivering messages as soon as message_consume() is called. +# start delivering messages as soon as message_subscribe() is called. session.message_subscribe(queue="message_queue", destination=consumer_tag) session.message_flow(consumer_tag, 0, 0xFFFFFFFF) # Kill these? diff --git a/qpid/python/examples/fanout/declare_queues.py b/qpid/python/examples/fanout/declare_queues.py index 3315f5bc14..8840ea38e1 100644 --- a/qpid/python/examples/fanout/declare_queues.py +++ b/qpid/python/examples/fanout/declare_queues.py @@ -1,6 +1,6 @@ #!/usr/bin/env python """ - config_direct_exchange.py + declare_queues.py Creates and binds a queue on an AMQP direct exchange. @@ -33,9 +33,6 @@ session.session_open() #----- Create a queue ------------------------------------- -# Create a queue named "listener" on channel 1, and bind it -# to the "amq.fanout" exchange. -# # queue_declare() creates an AMQP queue, which is held # on the broker. Published messages are sent to the AMQP queue, # from which messages are delivered to consumers. diff --git a/qpid/python/examples/fanout/fanout_consumer.py b/qpid/python/examples/fanout/fanout_consumer.py index e9a2291f4c..8d852ca753 100644 --- a/qpid/python/examples/fanout/fanout_consumer.py +++ b/qpid/python/examples/fanout/fanout_consumer.py @@ -1,6 +1,6 @@ #!/usr/bin/env python """ - direct_consumer.py + fanout_consumer.py This AMQP client reads messages from a message queue named "message_queue". @@ -40,9 +40,9 @@ session.session_open() consumer_tag = "consumer1" queue = client.queue(consumer_tag) -# Call message_consume() to tell the broker to deliver messages +# Call message_subscribe() to tell the broker to deliver messages # from the AMQP queue to this local client queue. The broker will -# start delivering messages as soon as message_consume() is called. +# start delivering messages as soon as message_subscribe() is called. session.message_subscribe(queue="message_queue", destination=consumer_tag) session.message_flow(consumer_tag, 0, 0xFFFFFFFF) diff --git a/qpid/python/examples/fanout/fanout_producer.py b/qpid/python/examples/fanout/fanout_producer.py index 92ca7b7ec0..d9d8f454c8 100644 --- a/qpid/python/examples/fanout/fanout_producer.py +++ b/qpid/python/examples/fanout/fanout_producer.py @@ -1,6 +1,6 @@ #!/usr/bin/env python """ - direct_producer.py + fanout_producer.py Publishes messages to an AMQP direct exchange, using the routing key "routing_key" diff --git a/qpid/python/examples/fanout/listener.py b/qpid/python/examples/fanout/listener.py index 4779466fd9..09dd7ddb80 100644 --- a/qpid/python/examples/fanout/listener.py +++ b/qpid/python/examples/fanout/listener.py @@ -1,6 +1,6 @@ #!/usr/bin/env python """ - direct_consumer.py + listener.py This AMQP client reads messages from a message queue named "message_queue". @@ -63,9 +63,9 @@ session.session_open() consumer_tag = "consumer1" queue = client.queue(consumer_tag) -# Call message_consume() to tell the broker to deliver messages +# Call message_subscribe() to tell the broker to deliver messages # from the AMQP queue to this local client queue. The broker will -# start delivering messages as soon as message_consume() is called. +# start delivering messages as soon as message_subscribe() is called. session.message_subscribe(queue="message_queue", destination=consumer_tag) session.message_flow(consumer_tag, 0, 0xFFFFFFFF) # Kill these? diff --git a/qpid/python/examples/pubsub/topic_subscriber.py b/qpid/python/examples/pubsub/topic_subscriber.py index 08682f0674..52ec67b77c 100644 --- a/qpid/python/examples/pubsub/topic_subscriber.py +++ b/qpid/python/examples/pubsub/topic_subscriber.py @@ -22,9 +22,9 @@ def dump_queue(client, queue_name): consumer_tag = queue_name # Use the queue name as the consumer tag - need a unique tag queue = client.queue(consumer_tag) - # Call basic_consume() to tell the broker to deliver messages + # Call message_subscribe() to tell the broker to deliver messages # from the AMQP queue to a local client queue. The broker will - # start delivering messages as soon as basic_consume() is called. + # start delivering messages as soon as message_subscribe() is called. session.message_subscribe(queue=queue_name, destination=consumer_tag) session.message_flow(consumer_tag, 0, 0xFFFFFFFF) diff --git a/qpid/python/examples/request-response/client.py b/qpid/python/examples/request-response/client.py index bc0cf8a55a..e218acce3d 100644 --- a/qpid/python/examples/request-response/client.py +++ b/qpid/python/examples/request-response/client.py @@ -24,7 +24,7 @@ def dump_queue(client, queue_name): # Call message_subscribe() to tell the broker to deliver messages # from the AMQP queue to a local client queue. The broker will - # start delivering messages as soon as basic_consume() is called. + # start delivering messages as soon as message_subscribe() is called. session.message_subscribe(queue=queue_name, destination=consumer_tag) session.message_flow(consumer_tag, 0, 0xFFFFFFFF) diff --git a/qpid/python/examples/request-response/server.py b/qpid/python/examples/request-response/server.py index 28bfd5ee4a..2730768a91 100644 --- a/qpid/python/examples/request-response/server.py +++ b/qpid/python/examples/request-response/server.py @@ -38,7 +38,7 @@ password="guest" client = Client(host, port, qpid.spec.load(amqp_spec)) client.start({"LOGIN": user, "PASSWORD": password}) -# Open Channel 1 so we can use it to manage our queue. +# Create a session and open it. session = client.session() session.session_open() -- cgit v1.2.1 From 56be271a9b61a7baec92b81ba84b9e9e2c51255d Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Fri, 8 Feb 2008 15:01:30 +0000 Subject: Refactored verify scripts, added verify for python Examples. To verify an example: /bin/verify See comments in bin/verify for more details. Changes: - Each example dir has its own verify script and verify.in. - Added sys.stdout.flush() to som python examples so verify can tell when they're ready. - Made python examples svn:executable. - C++ examples/Makefile.am runs python examples git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@619903 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/direct/declare_queues.py | 5 ++- qpid/python/examples/direct/direct_consumer.py | 5 ++- qpid/python/examples/direct/direct_producer.py | 5 ++- qpid/python/examples/direct/listener.py | 5 ++- qpid/python/examples/direct/verify | 3 ++ qpid/python/examples/direct/verify.in | 14 +++++++ qpid/python/examples/fanout/declare_queues.py | 5 ++- qpid/python/examples/fanout/fanout_consumer.py | 5 ++- qpid/python/examples/fanout/fanout_producer.py | 5 ++- qpid/python/examples/fanout/listener.py | 5 ++- qpid/python/examples/fanout/verify | 3 ++ qpid/python/examples/fanout/verify.in | 14 +++++++ qpid/python/examples/pubsub/topic_publisher.py | 6 +-- qpid/python/examples/pubsub/topic_subscriber.py | 9 +++-- qpid/python/examples/pubsub/verify | 4 ++ qpid/python/examples/pubsub/verify.in | 51 +++++++++++++++++++++++++ qpid/python/examples/request-response/client.py | 5 ++- qpid/python/examples/request-response/server.py | 6 ++- qpid/python/examples/request-response/verify | 5 +++ qpid/python/examples/request-response/verify.in | 14 +++++++ 20 files changed, 147 insertions(+), 27 deletions(-) mode change 100644 => 100755 qpid/python/examples/direct/declare_queues.py mode change 100644 => 100755 qpid/python/examples/direct/direct_consumer.py mode change 100644 => 100755 qpid/python/examples/direct/direct_producer.py mode change 100644 => 100755 qpid/python/examples/direct/listener.py create mode 100644 qpid/python/examples/direct/verify create mode 100644 qpid/python/examples/direct/verify.in mode change 100644 => 100755 qpid/python/examples/fanout/declare_queues.py mode change 100644 => 100755 qpid/python/examples/fanout/fanout_consumer.py mode change 100644 => 100755 qpid/python/examples/fanout/fanout_producer.py mode change 100644 => 100755 qpid/python/examples/fanout/listener.py create mode 100644 qpid/python/examples/fanout/verify create mode 100644 qpid/python/examples/fanout/verify.in mode change 100644 => 100755 qpid/python/examples/pubsub/topic_publisher.py mode change 100644 => 100755 qpid/python/examples/pubsub/topic_subscriber.py create mode 100644 qpid/python/examples/pubsub/verify create mode 100644 qpid/python/examples/pubsub/verify.in mode change 100644 => 100755 qpid/python/examples/request-response/client.py mode change 100644 => 100755 qpid/python/examples/request-response/server.py create mode 100644 qpid/python/examples/request-response/verify create mode 100644 qpid/python/examples/request-response/verify.in (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/direct/declare_queues.py b/qpid/python/examples/direct/declare_queues.py old mode 100644 new mode 100755 index 0160f66a1d..f39f0c3349 --- a/qpid/python/examples/direct/declare_queues.py +++ b/qpid/python/examples/direct/declare_queues.py @@ -9,6 +9,7 @@ """ import qpid +import sys from qpid.client import Client from qpid.content import Content from qpid.queue import Empty @@ -17,8 +18,8 @@ from qpid.queue import Empty # Set parameters for login -host="127.0.0.1" -port=5672 +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 amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" diff --git a/qpid/python/examples/direct/direct_consumer.py b/qpid/python/examples/direct/direct_consumer.py old mode 100644 new mode 100755 index 38b1ba30a0..85c1db0a93 --- a/qpid/python/examples/direct/direct_consumer.py +++ b/qpid/python/examples/direct/direct_consumer.py @@ -7,6 +7,7 @@ """ import qpid +import sys from qpid.client import Client from qpid.content import Content from qpid.queue import Empty @@ -16,8 +17,8 @@ from qpid.queue import Empty # Set parameters for login -host="127.0.0.1" -port=5672 +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 amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" diff --git a/qpid/python/examples/direct/direct_producer.py b/qpid/python/examples/direct/direct_producer.py old mode 100644 new mode 100755 index ff662477ce..2c07bfd8e7 --- a/qpid/python/examples/direct/direct_producer.py +++ b/qpid/python/examples/direct/direct_producer.py @@ -7,6 +7,7 @@ """ import qpid +import sys from qpid.client import Client from qpid.content import Content from qpid.queue import Empty @@ -15,8 +16,8 @@ from qpid.queue import Empty # Set parameters for login -host="127.0.0.1" -port=5672 +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 amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" diff --git a/qpid/python/examples/direct/listener.py b/qpid/python/examples/direct/listener.py old mode 100644 new mode 100755 index 8324cc76a6..2dbd502fa0 --- a/qpid/python/examples/direct/listener.py +++ b/qpid/python/examples/direct/listener.py @@ -8,6 +8,7 @@ """ import qpid +import sys from qpid.client import Client from qpid.content import Content from qpid.queue import Empty @@ -40,8 +41,8 @@ class Receiver: # Set parameters for login -host="127.0.0.1" -port=5672 +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 amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" diff --git a/qpid/python/examples/direct/verify b/qpid/python/examples/direct/verify new file mode 100644 index 0000000000..01d81a18a1 --- /dev/null +++ b/qpid/python/examples/direct/verify @@ -0,0 +1,3 @@ +# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify +clients ./declare_queues.py ./direct_producer.py ./direct_consumer.py +outputs ./declare_queues.py.out ./direct_producer.py.out ./direct_consumer.py.out diff --git a/qpid/python/examples/direct/verify.in b/qpid/python/examples/direct/verify.in new file mode 100644 index 0000000000..e0dca33039 --- /dev/null +++ b/qpid/python/examples/direct/verify.in @@ -0,0 +1,14 @@ +==== ./declare_queues.py.out +==== ./direct_producer.py.out +==== ./direct_consumer.py.out +message 0 +message 1 +message 2 +message 3 +message 4 +message 5 +message 6 +message 7 +message 8 +message 9 +That's all, folks! diff --git a/qpid/python/examples/fanout/declare_queues.py b/qpid/python/examples/fanout/declare_queues.py old mode 100644 new mode 100755 index 8840ea38e1..52f23f4f9a --- a/qpid/python/examples/fanout/declare_queues.py +++ b/qpid/python/examples/fanout/declare_queues.py @@ -9,6 +9,7 @@ """ import qpid +import sys from qpid.client import Client from qpid.content import Content from qpid.queue import Empty @@ -17,8 +18,8 @@ from qpid.queue import Empty # Set parameters for login -host="127.0.0.1" -port=5672 +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 amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" diff --git a/qpid/python/examples/fanout/fanout_consumer.py b/qpid/python/examples/fanout/fanout_consumer.py old mode 100644 new mode 100755 index 8d852ca753..b91ea35c0d --- a/qpid/python/examples/fanout/fanout_consumer.py +++ b/qpid/python/examples/fanout/fanout_consumer.py @@ -7,6 +7,7 @@ """ import qpid +import sys from qpid.client import Client from qpid.content import Content from qpid.queue import Empty @@ -16,8 +17,8 @@ from qpid.queue import Empty # Set parameters for login -host="127.0.0.1" -port=5672 +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 amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" diff --git a/qpid/python/examples/fanout/fanout_producer.py b/qpid/python/examples/fanout/fanout_producer.py old mode 100644 new mode 100755 index d9d8f454c8..9864c776c1 --- a/qpid/python/examples/fanout/fanout_producer.py +++ b/qpid/python/examples/fanout/fanout_producer.py @@ -7,6 +7,7 @@ """ import qpid +import sys from qpid.client import Client from qpid.content import Content from qpid.queue import Empty @@ -15,8 +16,8 @@ from qpid.queue import Empty # Set parameters for login -host="127.0.0.1" -port=5672 +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 amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" diff --git a/qpid/python/examples/fanout/listener.py b/qpid/python/examples/fanout/listener.py old mode 100644 new mode 100755 index 09dd7ddb80..8997c3698f --- a/qpid/python/examples/fanout/listener.py +++ b/qpid/python/examples/fanout/listener.py @@ -7,6 +7,7 @@ """ import qpid +import sys from qpid.client import Client from qpid.content import Content from qpid.queue import Empty @@ -39,8 +40,8 @@ class Receiver: # Set parameters for login -host="127.0.0.1" -port=5672 +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 amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" diff --git a/qpid/python/examples/fanout/verify b/qpid/python/examples/fanout/verify new file mode 100644 index 0000000000..f136ccd39b --- /dev/null +++ b/qpid/python/examples/fanout/verify @@ -0,0 +1,3 @@ +# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify +clients ./declare_queues.py ./fanout_producer.py ./fanout_consumer.py +outputs ./declare_queues.py.out ./fanout_producer.py.out ./fanout_consumer.py.out diff --git a/qpid/python/examples/fanout/verify.in b/qpid/python/examples/fanout/verify.in new file mode 100644 index 0000000000..c625c30773 --- /dev/null +++ b/qpid/python/examples/fanout/verify.in @@ -0,0 +1,14 @@ +==== ./declare_queues.py.out +==== ./fanout_producer.py.out +==== ./fanout_consumer.py.out +message 0 +message 1 +message 2 +message 3 +message 4 +message 5 +message 6 +message 7 +message 8 +message 9 +That's all, folks! diff --git a/qpid/python/examples/pubsub/topic_publisher.py b/qpid/python/examples/pubsub/topic_publisher.py old mode 100644 new mode 100755 index 1ff983b315..e302d58ad4 --- a/qpid/python/examples/pubsub/topic_publisher.py +++ b/qpid/python/examples/pubsub/topic_publisher.py @@ -8,6 +8,7 @@ """ import qpid +import sys from qpid.client import Client from qpid.content import Content from qpid.queue import Empty @@ -15,9 +16,8 @@ from qpid.queue import Empty #----- Initialization ----------------------------------- # Set parameters for login. - -host="127.0.0.1" -port=5672 +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 amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" diff --git a/qpid/python/examples/pubsub/topic_subscriber.py b/qpid/python/examples/pubsub/topic_subscriber.py old mode 100644 new mode 100755 index 52ec67b77c..a5c05ba177 --- a/qpid/python/examples/pubsub/topic_subscriber.py +++ b/qpid/python/examples/pubsub/topic_subscriber.py @@ -7,7 +7,7 @@ """ import base64 - +import sys import qpid from qpid.client import Client from qpid.content import Content @@ -60,8 +60,8 @@ def dump_queue(client, queue_name): # Set parameters for login -host="127.0.0.1" -port=5672 +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 amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" @@ -108,7 +108,8 @@ 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" +print "Queues created - please start the topic producer" +sys.stdout.flush() # Call dump_queue to print messages from each queue diff --git a/qpid/python/examples/pubsub/verify b/qpid/python/examples/pubsub/verify new file mode 100644 index 0000000000..bef233b4ff --- /dev/null +++ b/qpid/python/examples/pubsub/verify @@ -0,0 +1,4 @@ +# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify +background "Queues created" ./topic_subscriber.py +clients ./topic_publisher.py +outputs ./topic_publisher.py.out "topic_subscriber.py.out | remove_uuid64 | sort" diff --git a/qpid/python/examples/pubsub/verify.in b/qpid/python/examples/pubsub/verify.in new file mode 100644 index 0000000000..19dcf88312 --- /dev/null +++ b/qpid/python/examples/pubsub/verify.in @@ -0,0 +1,51 @@ +==== ./topic_publisher.py.out +==== topic_subscriber.py.out | remove_uuid64 | sort +message 0 +message 0 +message 0 +message 0 +message 0 +message 0 +message 0 +message 0 +message 1 +message 1 +message 1 +message 1 +message 1 +message 1 +message 1 +message 1 +message 2 +message 2 +message 2 +message 2 +message 2 +message 2 +message 2 +message 2 +message 3 +message 3 +message 3 +message 3 +message 3 +message 3 +message 3 +message 3 +message 4 +message 4 +message 4 +message 4 +message 4 +message 4 +message 4 +message 4 +Messages queue: europe +Messages queue: news +Messages queue: usa +Messages queue: weather +Queues created - please start the topic producer +That's all, folks! +That's all, folks! +That's all, folks! +That's all, folks! diff --git a/qpid/python/examples/request-response/client.py b/qpid/python/examples/request-response/client.py old mode 100644 new mode 100755 index e218acce3d..6561bb6fee --- a/qpid/python/examples/request-response/client.py +++ b/qpid/python/examples/request-response/client.py @@ -9,6 +9,7 @@ import base64 import qpid +import sys from qpid.client import Client from qpid.content import Content from qpid.queue import Empty @@ -59,8 +60,8 @@ def dump_queue(client, queue_name): # Set parameters for login -host="127.0.0.1" -port=5672 +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 amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" diff --git a/qpid/python/examples/request-response/server.py b/qpid/python/examples/request-response/server.py old mode 100644 new mode 100755 index 2730768a91..04b147d003 --- a/qpid/python/examples/request-response/server.py +++ b/qpid/python/examples/request-response/server.py @@ -6,6 +6,7 @@ """ import qpid +import sys from qpid.client import Client from qpid.content import Content from qpid.queue import Empty @@ -27,8 +28,8 @@ def respond(session, request): # Set parameters for login -host="127.0.0.1" -port=5672 +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 amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" @@ -61,6 +62,7 @@ session.message_flow(dest, 1, 0xFFFFFFFF) print "Request server running - run your client now." print "(Times out after 100 seconds ...)" +sys.stdout.flush() # Respond to each request diff --git a/qpid/python/examples/request-response/verify b/qpid/python/examples/request-response/verify new file mode 100644 index 0000000000..2a2d479077 --- /dev/null +++ b/qpid/python/examples/request-response/verify @@ -0,0 +1,5 @@ +# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify +background "Request server running" ./server.py +clients ./client.py +kill %% # Must kill the server. +outputs "./client.py.out | remove_uuid64" " server.py.out | remove_uuid64" diff --git a/qpid/python/examples/request-response/verify.in b/qpid/python/examples/request-response/verify.in new file mode 100644 index 0000000000..c02a423bcb --- /dev/null +++ b/qpid/python/examples/request-response/verify.in @@ -0,0 +1,14 @@ +==== ./client.py.out | remove_uuid64 +Request: Twas brilling, and the slithy toves +Request: Did gyre and gimble in the wabe. +Request: All mimsy were the borogroves, +Request: And the mome raths outgrabe. +Messages queue: ReplyTo: +Response: TWAS BRILLING, AND THE SLITHY TOVES +Response: DID GYRE AND GIMBLE IN THE WABE. +Response: ALL MIMSY WERE THE BOROGROVES, +Response: AND THE MOME RATHS OUTGRABE. +No more messages! +==== server.py.out | remove_uuid64 +Request server running - run your client now. +(Times out after 100 seconds ...) -- cgit v1.2.1 From bcc0ea7084a7a6a7c6fc983c6094d6c70c244e2c Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Mon, 11 Feb 2008 21:43:32 +0000 Subject: Fix errors in verify scripts. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@620619 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/direct/verify.in | 6 +++--- qpid/python/examples/fanout/verify.in | 6 +++--- qpid/python/examples/pubsub/verify.in | 2 +- qpid/python/examples/request-response/verify.in | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/direct/verify.in b/qpid/python/examples/direct/verify.in index e0dca33039..5e691619d9 100644 --- a/qpid/python/examples/direct/verify.in +++ b/qpid/python/examples/direct/verify.in @@ -1,6 +1,6 @@ -==== ./declare_queues.py.out -==== ./direct_producer.py.out -==== ./direct_consumer.py.out +==== declare_queues.py.out +==== direct_producer.py.out +==== direct_consumer.py.out message 0 message 1 message 2 diff --git a/qpid/python/examples/fanout/verify.in b/qpid/python/examples/fanout/verify.in index c625c30773..a5f57f0b4b 100644 --- a/qpid/python/examples/fanout/verify.in +++ b/qpid/python/examples/fanout/verify.in @@ -1,6 +1,6 @@ -==== ./declare_queues.py.out -==== ./fanout_producer.py.out -==== ./fanout_consumer.py.out +==== declare_queues.py.out +==== fanout_producer.py.out +==== fanout_consumer.py.out message 0 message 1 message 2 diff --git a/qpid/python/examples/pubsub/verify.in b/qpid/python/examples/pubsub/verify.in index 19dcf88312..69de08d17c 100644 --- a/qpid/python/examples/pubsub/verify.in +++ b/qpid/python/examples/pubsub/verify.in @@ -1,4 +1,4 @@ -==== ./topic_publisher.py.out +==== topic_publisher.py.out ==== topic_subscriber.py.out | remove_uuid64 | sort message 0 message 0 diff --git a/qpid/python/examples/request-response/verify.in b/qpid/python/examples/request-response/verify.in index c02a423bcb..f681253b3c 100644 --- a/qpid/python/examples/request-response/verify.in +++ b/qpid/python/examples/request-response/verify.in @@ -1,4 +1,4 @@ -==== ./client.py.out | remove_uuid64 +==== client.py.out | remove_uuid64 Request: Twas brilling, and the slithy toves Request: Did gyre and gimble in the wabe. Request: All mimsy were the borogroves, @@ -9,6 +9,6 @@ Response: DID GYRE AND GIMBLE IN THE WABE. Response: ALL MIMSY WERE THE BOROGROVES, Response: AND THE MOME RATHS OUTGRABE. No more messages! -==== server.py.out | remove_uuid64 +==== server.py.out | remove_uuid64 Request server running - run your client now. (Times out after 100 seconds ...) -- cgit v1.2.1 From 5034a2088eb20620225d2dfd4c2ae40b42b4c57d Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Fri, 15 Feb 2008 21:00:44 +0000 Subject: Updated c++ and python fanout examples and verify scripts. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@628169 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/fanout/declare_queues.py | 52 --------------- qpid/python/examples/fanout/fanout_consumer.py | 92 ++++++++++++++++---------- qpid/python/examples/fanout/verify | 6 +- qpid/python/examples/fanout/verify.in | 43 ++++++++---- 4 files changed, 91 insertions(+), 102 deletions(-) delete mode 100755 qpid/python/examples/fanout/declare_queues.py (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/fanout/declare_queues.py b/qpid/python/examples/fanout/declare_queues.py deleted file mode 100755 index 52f23f4f9a..0000000000 --- a/qpid/python/examples/fanout/declare_queues.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python -""" - declare_queues.py - - Creates and binds a queue on an AMQP direct exchange. - - All messages using the routing key "routing_key" are - sent to the queue named "message_queue". -""" - -import qpid -import sys -from qpid.client import Client -from qpid.content import Content -from qpid.queue import Empty - -#----- 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 -amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" -user="guest" -password="guest" - -# Create a client and log in to it. - -client = Client(host, port, qpid.spec.load(amqp_spec)) -client.start({"LOGIN": user, "PASSWORD": password}) - -session = client.session() -session.session_open() - -#----- Create a queue ------------------------------------- - -# queue_declare() creates an AMQP queue, which is held -# on the broker. Published messages are sent to the AMQP queue, -# from which messages are delivered to consumers. -# -# queue_bind() determines which messages are routed to a queue. -# Route all messages with the routing key "routing_key" to -# the AMQP queue named "message_queue". - -session.queue_declare(queue="message_queue") -session.queue_bind(exchange="amq.fanout", queue="message_queue") - -#----- Cleanup --------------------------------------------- - -# Clean up before exiting so there are no open threads. - -session.session_close() diff --git a/qpid/python/examples/fanout/fanout_consumer.py b/qpid/python/examples/fanout/fanout_consumer.py index b91ea35c0d..ef24bf35b2 100755 --- a/qpid/python/examples/fanout/fanout_consumer.py +++ b/qpid/python/examples/fanout/fanout_consumer.py @@ -5,13 +5,57 @@ This AMQP client reads messages from a message queue named "message_queue". """ - +import base64 import qpid import sys from qpid.client import Client from qpid.content import Content from qpid.queue import Empty +#----- Functions ------------------------------------------- + +def dump_queue(client, queue_name): + + print "Messages queue: " + queue_name + + consumer_tag = queue_name # Use the queue name as the consumer tag - need a unique tag + queue = client.queue(consumer_tag) + + # Call message_subscribe() to tell the broker to deliver messages + # from the AMQP queue to a local client queue. The broker will + # start delivering messages as soon as message_subscribe() is called. + + session.message_subscribe(queue=queue_name, destination=consumer_tag) + session.message_flow(consumer_tag, 0, 0xFFFFFFFF) + session.message_flow(consumer_tag, 1, 0xFFFFFFFF) + + print "Subscribed to queue " + queue_name + sys.stdout.flush() + + message = 0 + + while True: + try: + message = queue.get(timeout=10) + content = message.content.body + print "Response: " + content + except Empty: + print "No more messages!" + break + except: + print "Unexpected exception!" + break + + + # Messages are not removed from the queue until they + # are acknowledged. Using cumulative=True, all messages + # in the session up to and including the one identified + # by the delivery tag are acknowledged. This is more efficient, + # because there are fewer network round-trips. + + if message != 0: + message.complete(cumulative=True) + #----- Initialization -------------------------------------- @@ -29,44 +73,22 @@ client = Client(host, port, qpid.spec.load(amqp_spec)) client.start({"LOGIN": user, "PASSWORD": password}) session = client.session() -session.session_open() - -#----- Read from queue -------------------------------------------- - -# Now let's create a local client queue and tell it to read -# incoming messages. - -# The consumer tag identifies the client-side queue. - -consumer_tag = "consumer1" -queue = client.queue(consumer_tag) - -# Call message_subscribe() to tell the broker to deliver messages -# from the AMQP queue to this local client queue. The broker will -# start delivering messages as soon as message_subscribe() is called. - -session.message_subscribe(queue="message_queue", destination=consumer_tag) -session.message_flow(consumer_tag, 0, 0xFFFFFFFF) -session.message_flow(consumer_tag, 1, 0xFFFFFFFF) - -# Initialize 'final' and 'content', variables used to identify the last message. +session_info = session.session_open() +session_id = session_info.session_id -final = "That's all, folks!" # In a message body, signals the last message -content = "" # Content of the last message read +#----- Main Body -- ---------------------------------------- -message = None -while content != final: - message = queue.get(timeout=10) - content = message.content.body - print content +# Make a unique queue name for my queue from the session ID. +my_queue = base64.urlsafe_b64encode(session_id) +session.queue_declare(queue=my_queue) -# Messages are not removed from the queue until they are -# acknowledged. Using cumulative=True, all messages from the session -# up to and including the one identified by the delivery tag are -# acknowledged. This is more efficient, because there are fewer -# network round-trips. +# Bind my queue to the fanout exchange. No routing key is required +# the fanout exchange copies messages unconditionally to every +# bound queue +session.queue_bind(queue=my_queue, exchange="amq.fanout") -message.complete(cumulative=True) +# Dump the messages on the queue. +dump_queue(client, my_queue) #----- Cleanup ------------------------------------------------ diff --git a/qpid/python/examples/fanout/verify b/qpid/python/examples/fanout/verify index f136ccd39b..7650853e11 100644 --- a/qpid/python/examples/fanout/verify +++ b/qpid/python/examples/fanout/verify @@ -1,3 +1,5 @@ # See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -clients ./declare_queues.py ./fanout_producer.py ./fanout_consumer.py -outputs ./declare_queues.py.out ./fanout_producer.py.out ./fanout_consumer.py.out +background "Subscribed" ./fanout_consumer.py +background "Subscribed" ./fanout_consumer.py +clients ./fanout_producer.py +outputs ./fanout_producer.py.out "./fanout_consumer.py.out | remove_uuid64" "./fanout_consumer.pyX.out | remove_uuid64" diff --git a/qpid/python/examples/fanout/verify.in b/qpid/python/examples/fanout/verify.in index a5f57f0b4b..d5067b3850 100644 --- a/qpid/python/examples/fanout/verify.in +++ b/qpid/python/examples/fanout/verify.in @@ -1,14 +1,31 @@ -==== declare_queues.py.out ==== fanout_producer.py.out -==== fanout_consumer.py.out -message 0 -message 1 -message 2 -message 3 -message 4 -message 5 -message 6 -message 7 -message 8 -message 9 -That's all, folks! +==== fanout_consumer.py.out | remove_uuid64 +Messages queue: +Subscribed to queue +Response: message 0 +Response: message 1 +Response: message 2 +Response: message 3 +Response: message 4 +Response: message 5 +Response: message 6 +Response: message 7 +Response: message 8 +Response: message 9 +Response: That's all, folks! +No more messages! +==== fanout_consumer.pyX.out | remove_uuid64 +Messages queue: +Subscribed to queue +Response: message 0 +Response: message 1 +Response: message 2 +Response: message 3 +Response: message 4 +Response: message 5 +Response: message 6 +Response: message 7 +Response: message 8 +Response: message 9 +Response: That's all, folks! +No more messages! -- cgit v1.2.1 From 5fe0458b26fdf5ec233d8181201d3673a15006ae Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Thu, 1 May 2008 10:15:35 +0000 Subject: QPID-966: applied patch from rajith; altered to use uuid as session name; updated verify scripts for automated testing; re-enabled automated testing in c++ build git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@652469 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/direct/declare_queues.py | 31 +++++----- qpid/python/examples/direct/direct_consumer.py | 32 ++++++---- qpid/python/examples/direct/direct_producer.py | 34 ++++++----- qpid/python/examples/direct/listener.py | 31 ++++++---- qpid/python/examples/fanout/fanout_consumer.py | 43 ++++++++------ qpid/python/examples/fanout/fanout_producer.py | 32 +++++----- qpid/python/examples/fanout/verify | 2 +- qpid/python/examples/fanout/verify.in | 4 +- qpid/python/examples/pubsub/topic_publisher.py | 59 ++++++++----------- qpid/python/examples/pubsub/topic_subscriber.py | 78 +++++++++++++------------ qpid/python/examples/pubsub/verify | 2 +- qpid/python/examples/pubsub/verify.in | 2 +- qpid/python/examples/request-response/client.py | 61 ++++++++++--------- qpid/python/examples/request-response/server.py | 57 ++++++++++-------- qpid/python/examples/request-response/verify | 2 +- qpid/python/examples/request-response/verify.in | 4 +- 16 files changed, 252 insertions(+), 222 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/direct/declare_queues.py b/qpid/python/examples/direct/declare_queues.py index f39f0c3349..7041ce2f24 100755 --- a/qpid/python/examples/direct/declare_queues.py +++ b/qpid/python/examples/direct/declare_queues.py @@ -10,8 +10,10 @@ import qpid import sys -from qpid.client import Client -from qpid.content import Content +import os +from random import randint +from qpid.util import connect +from qpid.connection import Connection from qpid.queue import Empty #----- Initialization ----------------------------------- @@ -20,17 +22,20 @@ from qpid.queue import Empty 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 -amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" +amqp_spec="" -# Create a client and log in to it. +try: + amqp_spec = os.environ["AMQP_SPEC"] +except KeyError: + amqp_spec="/usr/share/amqp/amqp.0-10.xml" -client = Client(host, port, qpid.spec.load(amqp_spec)) -client.start({"LOGIN": user, "PASSWORD": password}) +# Create a connection. +conn = Connection (connect (host,port), qpid.spec.load(amqp_spec)) +conn.start() -session = client.session() -session.session_open() +session = conn.session(str(randint(1,64*1024))) #----- Create a queue ------------------------------------- @@ -38,15 +43,13 @@ session.session_open() # on the broker. Published messages are sent to the AMQP queue, # from which messages are delivered to consumers. # -# queue_bind() determines which messages are routed to a queue. -# Route all messages with the routing key "routing_key" to +# exchange_bind() determines which messages are routed to a queue. +# Route all messages with the binding key "routing_key" to # the AMQP queue named "message_queue". session.queue_declare(queue="message_queue") -session.queue_bind(exchange="amq.direct", queue="message_queue", routing_key="routing_key") +session.exchange_bind(exchange="amq.direct", queue="message_queue", binding_key="routing_key") #----- Cleanup --------------------------------------------- -session.session_close() - - +session.close(timeout=10) diff --git a/qpid/python/examples/direct/direct_consumer.py b/qpid/python/examples/direct/direct_consumer.py index 85c1db0a93..91d85cee1a 100755 --- a/qpid/python/examples/direct/direct_consumer.py +++ b/qpid/python/examples/direct/direct_consumer.py @@ -8,8 +8,11 @@ import qpid import sys -from qpid.client import Client -from qpid.content import Content +import os +from random import randint +from qpid.util import connect +from qpid.connection import Connection +from qpid.datatypes import Message, RangedSet from qpid.queue import Empty @@ -19,17 +22,20 @@ from qpid.queue import Empty 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 -amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" +amqp_spec="" -# Create a client and log in to it. +try: + amqp_spec = os.environ["AMQP_SPEC"] +except KeyError: + amqp_spec="/usr/share/amqp/amqp.0-10.xml" -client = Client(host, port, qpid.spec.load(amqp_spec)) -client.start({"LOGIN": user, "PASSWORD": password}) +# Create a connection. +conn = Connection (connect (host,port), qpid.spec.load(amqp_spec)) +conn.start() -session = client.session() -session.session_open() +session = conn.session(str(randint(1,64*1024))) #----- Read from queue -------------------------------------------- @@ -39,7 +45,7 @@ session.session_open() # The consumer tag identifies the client-side queue. consumer_tag = "consumer1" -queue = client.queue(consumer_tag) +queue = session.incoming(consumer_tag) # Call message_consume() to tell the broker to deliver messages # from the AMQP queue to this local client queue. The broker will @@ -57,7 +63,8 @@ content = "" # Content of the last message read message = None while content != final: message = queue.get(timeout=10) - content = message.content.body + content = message.body + session.message_accept(RangedSet(message.id)) print content # Messages are not removed from the queue until they are @@ -66,11 +73,12 @@ while content != final: # acknowledged. This is more efficient, because there are fewer # network round-trips. -message.complete(cumulative=True) +#message.complete(cumulative=True) +# ? Is there an equivakent to the above in the new API ? #----- Cleanup ------------------------------------------------ # Clean up before exiting so there are no open threads. # -session.session_close() +session.close(timeout=10) diff --git a/qpid/python/examples/direct/direct_producer.py b/qpid/python/examples/direct/direct_producer.py index 2c07bfd8e7..7c4e30d96e 100755 --- a/qpid/python/examples/direct/direct_producer.py +++ b/qpid/python/examples/direct/direct_producer.py @@ -8,8 +8,11 @@ import qpid import sys -from qpid.client import Client -from qpid.content import Content +import os +from random import randint +from qpid.util import connect +from qpid.connection import Connection +from qpid.datatypes import Message from qpid.queue import Empty #----- Initialization ----------------------------------- @@ -18,34 +21,33 @@ from qpid.queue import Empty 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 -amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" +amqp_spec="" -# Create a client and log in to it. +try: + amqp_spec = os.environ["AMQP_SPEC"] +except KeyError: + amqp_spec="/usr/share/amqp/amqp.0-10.xml" -client = Client(host, port, qpid.spec.load(amqp_spec)) -client.start({"LOGIN": user, "PASSWORD": password}) +# Create a connection. +conn = Connection (connect (host,port), qpid.spec.load(amqp_spec)) +conn.start() -session = client.session() -session.session_open() +session = conn.session(str(randint(1,64*1024))) #----- Publish some messages ------------------------------ # Create some messages and put them on the broker. +props = session.delivery_properties(routing_key="routing_key") for i in range(10): - message = Content("message " + str(i)) - message["routing_key"] = "routing_key" - session.message_transfer(destination="amq.direct", content=message) + session.message_transfer("amq.direct",None, None, Message(props,"message " + str(i))) -final="That's all, folks!" -message = Content(final) -message["routing_key"] = "routing_key" -session.message_transfer(destination="amq.direct", content=message) +session.message_transfer("amq.direct",None,None, Message(props,"That's all, folks!")) #----- Cleanup -------------------------------------------- # Clean up before exiting so there are no open threads. -session.session_close() +session.close(timeout=10) diff --git a/qpid/python/examples/direct/listener.py b/qpid/python/examples/direct/listener.py index 2dbd502fa0..aa60b1c501 100755 --- a/qpid/python/examples/direct/listener.py +++ b/qpid/python/examples/direct/listener.py @@ -9,8 +9,11 @@ import qpid import sys -from qpid.client import Client -from qpid.content import Content +import os +from random import randint +from qpid.util import connect +from qpid.connection import Connection +from qpid.datatypes import Message, RangedSet from qpid.queue import Empty from time import sleep @@ -24,7 +27,8 @@ class Receiver: return self.finalReceived def Handler (self, message): - content = message.content.body + content = message.body + session.message_accept(RangedSet(message.id)) print content if content == "That's all, folks!": self.finalReceived = True @@ -34,7 +38,7 @@ class Receiver: # up to and including the one identified by the delivery tag are # acknowledged. This is more efficient, because there are fewer # network round-trips. - message.complete(cumulative=True) + #message.complete(cumulative=True) #----- Initialization -------------------------------------- @@ -43,17 +47,20 @@ class Receiver: 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 -amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" +amqp_spec="" -# Create a client and log in to it. +try: + amqp_spec = os.environ["AMQP_SPEC"] +except KeyError: + amqp_spec="/usr/share/amqp/amqp.0-10.xml" -client = Client(host, port, qpid.spec.load(amqp_spec)) -client.start({"LOGIN": user, "PASSWORD": password}) +# Create a connection. +conn = Connection (connect (host,port), qpid.spec.load(amqp_spec)) +conn.start() -session = client.session() -session.session_open() +session = conn.session(str(randint(1,64*1024))) #----- Read from queue -------------------------------------------- @@ -63,7 +70,7 @@ session.session_open() # The consumer tag identifies the client-side queue. consumer_tag = "consumer1" -queue = client.queue(consumer_tag) +queue = session.incoming(consumer_tag) # Call message_subscribe() to tell the broker to deliver messages # from the AMQP queue to this local client queue. The broker will @@ -85,4 +92,4 @@ while not receiver.isFinal (): # Clean up before exiting so there are no open threads. # -session.session_close() +session.close(timeout=10) diff --git a/qpid/python/examples/fanout/fanout_consumer.py b/qpid/python/examples/fanout/fanout_consumer.py index ef24bf35b2..b82d8045ff 100755 --- a/qpid/python/examples/fanout/fanout_consumer.py +++ b/qpid/python/examples/fanout/fanout_consumer.py @@ -5,21 +5,22 @@ This AMQP client reads messages from a message queue named "message_queue". """ -import base64 import qpid import sys -from qpid.client import Client -from qpid.content import Content +import os +from qpid.util import connect +from qpid.connection import Connection +from qpid.datatypes import Message, RangedSet, uuid4 from qpid.queue import Empty #----- Functions ------------------------------------------- -def dump_queue(client, queue_name): +def dump_queue(session, queue_name): print "Messages queue: " + queue_name consumer_tag = queue_name # Use the queue name as the consumer tag - need a unique tag - queue = client.queue(consumer_tag) + queue = session.incoming(queue_name) # Call message_subscribe() to tell the broker to deliver messages # from the AMQP queue to a local client queue. The broker will @@ -37,7 +38,8 @@ def dump_queue(client, queue_name): while True: try: message = queue.get(timeout=10) - content = message.content.body + content = message.body + session.message_accept(RangedSet(message.id)) print "Response: " + content except Empty: print "No more messages!" @@ -53,8 +55,8 @@ def dump_queue(client, queue_name): # by the delivery tag are acknowledged. This is more efficient, # because there are fewer network round-trips. - if message != 0: - message.complete(cumulative=True) + #if message != 0: + # message.complete(cumulative=True) #----- Initialization -------------------------------------- @@ -63,36 +65,39 @@ def dump_queue(client, queue_name): 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 -amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" +amqp_spec="" -# Create a client and log in to it. +try: + amqp_spec = os.environ["AMQP_SPEC"] +except KeyError: + amqp_spec="/usr/share/amqp/amqp.0-10.xml" -client = Client(host, port, qpid.spec.load(amqp_spec)) -client.start({"LOGIN": user, "PASSWORD": password}) +# Create a connection. +conn = Connection (connect (host,port), qpid.spec.load(amqp_spec)) +conn.start() -session = client.session() -session_info = session.session_open() -session_id = session_info.session_id +session_id = str(uuid4()) +session = conn.session(session_id) #----- Main Body -- ---------------------------------------- # Make a unique queue name for my queue from the session ID. -my_queue = base64.urlsafe_b64encode(session_id) +my_queue = session_id session.queue_declare(queue=my_queue) # Bind my queue to the fanout exchange. No routing key is required # the fanout exchange copies messages unconditionally to every # bound queue -session.queue_bind(queue=my_queue, exchange="amq.fanout") +session.exchange_bind(queue=my_queue, exchange="amq.fanout") # Dump the messages on the queue. -dump_queue(client, my_queue) +dump_queue(session, my_queue) #----- Cleanup ------------------------------------------------ # Clean up before exiting so there are no open threads. # -session.session_close() +session.close(timeout=10) diff --git a/qpid/python/examples/fanout/fanout_producer.py b/qpid/python/examples/fanout/fanout_producer.py index 9864c776c1..1b5ea6995e 100755 --- a/qpid/python/examples/fanout/fanout_producer.py +++ b/qpid/python/examples/fanout/fanout_producer.py @@ -5,11 +5,13 @@ Publishes messages to an AMQP direct exchange, using the routing key "routing_key" """ - import qpid import sys -from qpid.client import Client -from qpid.content import Content +import os +from random import randint +from qpid.util import connect +from qpid.connection import Connection +from qpid.datatypes import Message from qpid.queue import Empty #----- Initialization ----------------------------------- @@ -18,32 +20,32 @@ from qpid.queue import Empty 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 -amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" +amqp_spec="" -# Create a client and log in to it. +try: + amqp_spec = os.environ["AMQP_SPEC"] +except KeyError: + amqp_spec="/usr/share/amqp/amqp.0-10.xml" -client = Client(host, port, qpid.spec.load(amqp_spec)) -client.start({"LOGIN": user, "PASSWORD": password}) +# Create a connection. +conn = Connection (connect (host,port), qpid.spec.load(amqp_spec)) +conn.start() -session = client.session() -session.session_open() +session = conn.session(str(randint(1,64*1024))) #----- Publish some messages ------------------------------ # Create some messages and put them on the broker. for i in range(10): - message = Content(body="message " + str(i)) - session.message_transfer(destination="amq.fanout", content=message) + session.message_transfer("amq.fanout", None, None ,Message("message " + str(i))) -final="That's all, folks!" -message=Content(final) -session.message_transfer(destination="amq.fanout", content=message) +session.message_transfer("amq.fanout", None, None, Message("That's all, folks!")) #----- Cleanup -------------------------------------------- # Clean up before exiting so there are no open threads. -session.session_close() +session.close(timeout=10) diff --git a/qpid/python/examples/fanout/verify b/qpid/python/examples/fanout/verify index 7650853e11..6a3132a94f 100644 --- a/qpid/python/examples/fanout/verify +++ b/qpid/python/examples/fanout/verify @@ -2,4 +2,4 @@ background "Subscribed" ./fanout_consumer.py background "Subscribed" ./fanout_consumer.py clients ./fanout_producer.py -outputs ./fanout_producer.py.out "./fanout_consumer.py.out | remove_uuid64" "./fanout_consumer.pyX.out | remove_uuid64" +outputs ./fanout_producer.py.out "./fanout_consumer.py.out | remove_uuid" "./fanout_consumer.pyX.out | remove_uuid" diff --git a/qpid/python/examples/fanout/verify.in b/qpid/python/examples/fanout/verify.in index d5067b3850..30dfeb9e69 100644 --- a/qpid/python/examples/fanout/verify.in +++ b/qpid/python/examples/fanout/verify.in @@ -1,5 +1,5 @@ ==== fanout_producer.py.out -==== fanout_consumer.py.out | remove_uuid64 +==== fanout_consumer.py.out | remove_uuid Messages queue: Subscribed to queue Response: message 0 @@ -14,7 +14,7 @@ Response: message 8 Response: message 9 Response: That's all, folks! No more messages! -==== fanout_consumer.pyX.out | remove_uuid64 +==== fanout_consumer.pyX.out | remove_uuid Messages queue: Subscribed to queue Response: message 0 diff --git a/qpid/python/examples/pubsub/topic_publisher.py b/qpid/python/examples/pubsub/topic_publisher.py index e302d58ad4..b79896eaf6 100755 --- a/qpid/python/examples/pubsub/topic_publisher.py +++ b/qpid/python/examples/pubsub/topic_publisher.py @@ -9,8 +9,11 @@ import qpid import sys -from qpid.client import Client -from qpid.content import Content +import os +from random import randint +from qpid.util import connect +from qpid.connection import Connection +from qpid.datatypes import Message from qpid.queue import Empty #----- Initialization ----------------------------------- @@ -18,18 +21,20 @@ from qpid.queue import Empty # 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 -amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" +amqp_spec="" -# Create a client and log in to it. +try: + amqp_spec = os.environ["AMQP_SPEC"] +except KeyError: + amqp_spec="/usr/share/amqp/amqp.0-10.xml" -spec = qpid.spec.load(amqp_spec) -client = Client(host, port, spec) -client.start({"LOGIN": user, "PASSWORD": password}) +# Create a connection. +conn = Connection (connect (host,port), qpid.spec.load(amqp_spec)) +conn.start() -session = client.session() -session.session_open() +session = conn.session(str(randint(1,64*1024))) #----- Publish some messages ------------------------------ @@ -37,44 +42,30 @@ session.session_open() # 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 - -for i in range(5): - message = Content("message " + str(i)) - message["routing_key"] = "usa.news" - session.message_transfer(destination="amq.topic", content=message) +send_msg("usa.news") # 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) +send_msg("usa.weather") # 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) +send_msg("europe.news") # 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) +send_msg("europe.weather") # Signal termination - -message = Content("That's all, folks!") -message["routing_key"] = "control" -session.message_transfer(destination="amq.topic", content=message) +props = session.delivery_properties(routing_key="control") +session.message_transfer("amq.topic",None, None, Message(props,"That's all, folks!")) #----- Cleanup -------------------------------------------- # Clean up before exiting so there are no open threads. -session.session_close() +session.close(timeout=10) diff --git a/qpid/python/examples/pubsub/topic_subscriber.py b/qpid/python/examples/pubsub/topic_subscriber.py index a5c05ba177..6908be5471 100755 --- a/qpid/python/examples/pubsub/topic_subscriber.py +++ b/qpid/python/examples/pubsub/topic_subscriber.py @@ -3,24 +3,25 @@ topic_subscriber.py This subscriber creates private queues and binds them - to the topics "usa.#", "europe.#", "#.news", and "#.weather". + to the topics 'usa.#', 'europe.#', '#.news', and '#.weather'. """ -import base64 -import sys import qpid -from qpid.client import Client -from qpid.content import Content +import sys +import os +from qpid.util import connect +from qpid.connection import Connection +from qpid.datatypes import Message, RangedSet, uuid4 from qpid.queue import Empty #----- Functions ------------------------------------------- -def dump_queue(client, queue_name): +def dump_queue(queue_name): print "Messages queue: " + queue_name consumer_tag = queue_name # Use the queue name as the consumer tag - need a unique tag - queue = client.queue(consumer_tag) + queue = session.incoming(consumer_tag) # Call message_subscribe() to tell the broker to deliver messages # from the AMQP queue to a local client queue. The broker will @@ -37,11 +38,12 @@ def dump_queue(client, queue_name): while content != final: try: message = queue.get() - content = message.content.body + content = message.body + session.message_accept(RangedSet(message.id)) print content except Empty: - if message != 0: - message.complete(cumulative=True) + #if message != 0: + # message.complete(cumulative=True) print "No more messages!" return @@ -52,8 +54,8 @@ def dump_queue(client, queue_name): # by the delivery tag are acknowledged. This is more efficient, # because there are fewer network round-trips. - if message != 0: - message.complete(cumulative=True) + #if message != 0: + # message.complete(cumulative=True) #----- Initialization -------------------------------------- @@ -62,27 +64,29 @@ def dump_queue(client, queue_name): 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 -amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" +amqp_spec="" -# Create a client and log in to it. +try: + amqp_spec = os.environ["AMQP_SPEC"] +except KeyError: + amqp_spec="/usr/share/amqp/amqp.0-10.xml" -spec = qpid.spec.load(amqp_spec) -client = Client(host, port, spec) -client.start({"LOGIN": user, "PASSWORD": password}) +# Create a connection. +conn = Connection (connect (host,port), qpid.spec.load(amqp_spec)) +conn.start() -session = client.session() -session_info = session.session_open() -session_id = session_info.session_id +session_id = str(uuid4()) +session = conn.session(session_id) #----- Main Body -- ---------------------------------------- -news = "news" + base64.urlsafe_b64encode(session_id) -weather = "weather" + base64.urlsafe_b64encode(session_id) -usa = "usa" + base64.urlsafe_b64encode(session_id) -europe = "europe" + base64.urlsafe_b64encode(session_id) +news = "news" + session_id +weather = "weather" + session_id +usa = "usa" + session_id +europe = "europe" + session_id session.queue_declare(queue=news, exclusive=True) session.queue_declare(queue=weather, exclusive=True) @@ -94,17 +98,17 @@ session.queue_declare(queue=europe, exclusive=True) # The '#' symbol matches one component of a multipart name, e.g. "#.news" matches # "europe.news" or "usa.news". -session.queue_bind(exchange="amq.topic", queue=news, routing_key="#.news") -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.#") +session.exchange_bind(exchange="amq.topic", queue=news, binding_key="#.news") +session.exchange_bind(exchange="amq.topic", queue=weather, binding_key="#.weather") +session.exchange_bind(exchange="amq.topic", queue=usa, binding_key="usa.#") +session.exchange_bind(exchange="amq.topic", queue=europe, binding_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") +session.exchange_bind(exchange="amq.topic", queue=news, binding_key="control") +session.exchange_bind(exchange="amq.topic", queue=weather, binding_key="control") +session.exchange_bind(exchange="amq.topic", queue=usa, binding_key="control") +session.exchange_bind(exchange="amq.topic", queue=europe, binding_key="control") # Remind the user to start the topic producer @@ -113,13 +117,13 @@ sys.stdout.flush() # Call dump_queue to print messages from each queue -dump_queue(client, news) -dump_queue(client, weather) -dump_queue(client, usa) -dump_queue(client, europe) +dump_queue(news) +dump_queue(weather) +dump_queue(usa) +dump_queue(europe) #----- Cleanup ------------------------------------------------ # Clean up before exiting so there are no open threads. -session.session_close() +session.close(timeout=10) diff --git a/qpid/python/examples/pubsub/verify b/qpid/python/examples/pubsub/verify index bef233b4ff..963d2e32e1 100644 --- a/qpid/python/examples/pubsub/verify +++ b/qpid/python/examples/pubsub/verify @@ -1,4 +1,4 @@ # See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify background "Queues created" ./topic_subscriber.py clients ./topic_publisher.py -outputs ./topic_publisher.py.out "topic_subscriber.py.out | remove_uuid64 | sort" +outputs ./topic_publisher.py.out "topic_subscriber.py.out | remove_uuid | sort" diff --git a/qpid/python/examples/pubsub/verify.in b/qpid/python/examples/pubsub/verify.in index 69de08d17c..2f6da09ec5 100644 --- a/qpid/python/examples/pubsub/verify.in +++ b/qpid/python/examples/pubsub/verify.in @@ -1,5 +1,5 @@ ==== topic_publisher.py.out -==== topic_subscriber.py.out | remove_uuid64 | sort +==== topic_subscriber.py.out | remove_uuid | sort message 0 message 0 message 0 diff --git a/qpid/python/examples/request-response/client.py b/qpid/python/examples/request-response/client.py index 6561bb6fee..8f7d430d1b 100755 --- a/qpid/python/examples/request-response/client.py +++ b/qpid/python/examples/request-response/client.py @@ -6,22 +6,22 @@ """ -import base64 - import qpid import sys -from qpid.client import Client -from qpid.content import Content +import os +from qpid.util import connect +from qpid.connection import Connection +from qpid.datatypes import Message, RangedSet, uuid4 from qpid.queue import Empty #----- Functions ------------------------------------------- -def dump_queue(client, queue_name): +def dump_queue(queue_name): print "Messages queue: " + queue_name consumer_tag = queue_name # Use the queue name as the consumer tag - need a unique tag - queue = client.queue(consumer_tag) + queue = session.incoming(consumer_tag) # Call message_subscribe() to tell the broker to deliver messages # from the AMQP queue to a local client queue. The broker will @@ -36,7 +36,8 @@ def dump_queue(client, queue_name): while True: try: message = queue.get(timeout=10) - content = message.content.body + content = message.body + session.message_accept(RangedSet(message.id)) print "Response: " + content except Empty: print "No more messages!" @@ -52,8 +53,8 @@ def dump_queue(client, queue_name): # by the delivery tag are acknowledged. This is more efficient, # because there are fewer network round-trips. - if message != 0: - message.complete(cumulative=True) + #if message != 0: + # message.complete(cumulative=True) #----- Initialization -------------------------------------- @@ -62,21 +63,21 @@ def dump_queue(client, queue_name): 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 -amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" +amqp_spec="" -# 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}) +try: + amqp_spec = os.environ["AMQP_SPEC"] +except KeyError: + amqp_spec="/usr/share/amqp/amqp.0-10.xml" -# Open the session. Save the session id. +# Create a connection. +conn = Connection (connect (host,port), qpid.spec.load(amqp_spec)) +conn.start() -session = client.session() -session_info = session.session_open() -session_id = session_info.session_id +session_id = str(uuid4()) +session = conn.session(session_id) #----- Main Body -- ---------------------------------------- @@ -84,9 +85,9 @@ session_id = session_info.session_id # same string as the name of the queue and the name of the routing # key. -replyTo = "ReplyTo:" + base64.urlsafe_b64encode(session_id) +replyTo = "ReplyTo:" + session_id session.queue_declare(queue=replyTo, exclusive=True) -session.queue_bind(exchange="amq.direct", queue=replyTo, routing_key=replyTo) +session.exchange_bind(exchange="amq.direct", queue=replyTo, binding_key=replyTo) # Send some messages to the server's request queue @@ -95,22 +96,20 @@ lines = ["Twas brilling, and the slithy toves", "All mimsy were the borogroves,", "And the mome raths outgrabe."] -for l in lines: - print "Request: " + l - request=Content(l) - request["routing_key"] = "request" - request["reply_to"] = client.spec.struct("reply_to") - request["reply_to"]["exchange_name"] = "amq.direct" - request["reply_to"]["routing_key"] = replyTo - session.message_transfer(destination="amq.direct", content=request) +for ln in lines: + print "Request: " + ln + mp = session.message_properties() + mp.reply_to = session.reply_to("amq.direct", replyTo) + dp = session.delivery_properties(routing_key="request") + session.message_transfer("amq.direct", None, None, Message(mp,dp,ln)) # Now see what messages the server sent to our replyTo queue -dump_queue(client, replyTo) +dump_queue(replyTo) #----- Cleanup ------------------------------------------------ # Clean up before exiting so there are no open threads. -session.session_close() +session.close(timeout=10) diff --git a/qpid/python/examples/request-response/server.py b/qpid/python/examples/request-response/server.py index 04b147d003..71c3161495 100755 --- a/qpid/python/examples/request-response/server.py +++ b/qpid/python/examples/request-response/server.py @@ -4,52 +4,61 @@ Server for a client/server example """ - import qpid import sys -from qpid.client import Client -from qpid.content import Content +import os +from random import randint +from qpid.util import connect +from qpid.connection import Connection +from qpid.datatypes import Message, RangedSet, uuid4 from qpid.queue import Empty #----- Functions ------------------------------------------- +def getProperty(msg, name): + for h in msg.headers: + if hasattr(h, name): return getattr(h, name) + return None def respond(session, request): # The routing key for the response is the request's reply-to # property. The body for the response is the request's body, # converted to upper case. - - response=Content(request.body.upper()) - response["routing_key"] = request["reply_to"]["routing_key"] - session.message_transfer(destination=request["reply_to"]["exchange_name"], content=response) + reply_to = getProperty(request,"reply_to") + if reply_to == None: + raise Exception("reply to property needs to be there") + + props = session.delivery_properties(routing_key=reply_to["routing_key"]) + session.message_transfer(reply_to["exchange"],None, None, Message(props,request.body.upper())) #----- 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 -amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" user="guest" password="guest" - -# Create a client and log in to it. - -client = Client(host, port, qpid.spec.load(amqp_spec)) -client.start({"LOGIN": user, "PASSWORD": password}) - -# Create a session and open it. - -session = client.session() -session.session_open() +amqp_spec="" + +try: + amqp_spec = os.environ["AMQP_SPEC"] +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_id = str(uuid4()) +session = conn.session(session_id) #----- Main Body -- ---------------------------------------- # Create a request queue and subscribe to it session.queue_declare(queue="request", exclusive=True) -session.queue_bind(exchange="amq.direct", queue="request", routing_key="request") +session.exchange_bind(exchange="amq.direct", queue="request", binding_key="request") dest = "request_destination" @@ -66,7 +75,7 @@ sys.stdout.flush() # Respond to each request -queue = client.queue(dest) +queue = session.incoming(dest) # If we get a message, send it back to the user (as indicated in the # ReplyTo property) @@ -74,8 +83,8 @@ queue = client.queue(dest) while True: try: request = queue.get(timeout=100) - respond(session, request.content) - request.complete() + respond(session, request) + session.message_accept(RangedSet(request.id)) except Empty: print "No more messages!" break; @@ -85,4 +94,4 @@ while True: # Clean up before exiting so there are no open threads. -session.session_close() +session.close(timeout=10) diff --git a/qpid/python/examples/request-response/verify b/qpid/python/examples/request-response/verify index 2a2d479077..cf8151d4e4 100644 --- a/qpid/python/examples/request-response/verify +++ b/qpid/python/examples/request-response/verify @@ -2,4 +2,4 @@ background "Request server running" ./server.py clients ./client.py kill %% # Must kill the server. -outputs "./client.py.out | remove_uuid64" " server.py.out | remove_uuid64" +outputs "./client.py.out | remove_uuid" " server.py.out | remove_uuid" diff --git a/qpid/python/examples/request-response/verify.in b/qpid/python/examples/request-response/verify.in index f681253b3c..8d7f732ec8 100644 --- a/qpid/python/examples/request-response/verify.in +++ b/qpid/python/examples/request-response/verify.in @@ -1,4 +1,4 @@ -==== client.py.out | remove_uuid64 +==== client.py.out | remove_uuid Request: Twas brilling, and the slithy toves Request: Did gyre and gimble in the wabe. Request: All mimsy were the borogroves, @@ -9,6 +9,6 @@ Response: DID GYRE AND GIMBLE IN THE WABE. Response: ALL MIMSY WERE THE BOROGROVES, Response: AND THE MOME RATHS OUTGRABE. No more messages! -==== server.py.out | remove_uuid64 +==== server.py.out | remove_uuid Request server running - run your client now. (Times out after 100 seconds ...) -- cgit v1.2.1 From 5829e87a54c3bb8972ea993882976f188d866587 Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Wed, 7 May 2008 16:03:08 +0000 Subject: QPID-979: added convenience accessors for headers git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@654158 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/request-response/server.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/request-response/server.py b/qpid/python/examples/request-response/server.py index 71c3161495..4377571248 100755 --- a/qpid/python/examples/request-response/server.py +++ b/qpid/python/examples/request-response/server.py @@ -7,29 +7,24 @@ 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, RangedSet, uuid4 from qpid.queue import Empty #----- Functions ------------------------------------------- -def getProperty(msg, name): - for h in msg.headers: - if hasattr(h, name): return getattr(h, name) - return None - def respond(session, request): # The routing key for the response is the request's reply-to # property. The body for the response is the request's body, # converted to upper case. - reply_to = getProperty(request,"reply_to") + message_properties = request.get("message_properties") + reply_to = message_properties.reply_to if reply_to == None: - raise Exception("reply to property needs to be there") - - props = session.delivery_properties(routing_key=reply_to["routing_key"]) + raise Exception("reply to property needs to be there") + + props = session.delivery_properties(routing_key=reply_to["routing_key"]) session.message_transfer(reply_to["exchange"],None, None, Message(props,request.body.upper())) #----- Initialization -------------------------------------- @@ -40,16 +35,16 @@ port=len(sys.argv) > 2 and int(sys.argv[2]) or 5672 user="guest" password="guest" amqp_spec="" - + try: amqp_spec = os.environ["AMQP_SPEC"] 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_id = str(uuid4()) session = conn.session(session_id) -- cgit v1.2.1 From 48454ce071be26b4662a137e41e7421f7b3f8d69 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Mon, 12 May 2008 17:23:21 +0000 Subject: QPID-1044: Part of patch from Jonathan Robie + changes to verify scripts to keep automated testing working. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@655568 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/direct/declare_queues.py | 31 +++++-- qpid/python/examples/direct/direct_consumer.py | 51 ++++++----- qpid/python/examples/direct/direct_producer.py | 32 ++++--- qpid/python/examples/direct/listener.py | 59 ++++++------ qpid/python/examples/fanout/fanout_consumer.py | 115 +++++++++++------------- qpid/python/examples/fanout/fanout_producer.py | 33 ++++--- qpid/python/examples/fanout/listener.py | 83 ++++++++++------- qpid/python/examples/fanout/verify.in | 48 +++++----- qpid/python/examples/pubsub/topic_publisher.py | 45 ++++++---- qpid/python/examples/pubsub/topic_subscriber.py | 98 +++++++++++--------- qpid/python/examples/pubsub/verify.in | 92 ++++++++++--------- qpid/python/examples/request-response/client.py | 89 +++++++++--------- qpid/python/examples/request-response/server.py | 48 ++++++---- qpid/python/examples/request-response/verify.in | 2 +- 14 files changed, 469 insertions(+), 357 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/direct/declare_queues.py b/qpid/python/examples/direct/declare_queues.py index 7041ce2f24..deea0a3ccc 100755 --- a/qpid/python/examples/direct/declare_queues.py +++ b/qpid/python/examples/direct/declare_queues.py @@ -8,34 +8,47 @@ sent to the queue named "message_queue". """ +# Common includes + 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, RangedSet, uuid4 from qpid.queue import Empty #----- 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 +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"] except KeyError: - amqp_spec="/usr/share/amqp/amqp.0-10.xml" + 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())) #----- Create a queue ------------------------------------- diff --git a/qpid/python/examples/direct/direct_consumer.py b/qpid/python/examples/direct/direct_consumer.py index 91d85cee1a..f2018bbbb8 100755 --- a/qpid/python/examples/direct/direct_consumer.py +++ b/qpid/python/examples/direct/direct_consumer.py @@ -12,7 +12,7 @@ import os from random import randint from qpid.util import connect from qpid.connection import Connection -from qpid.datatypes import Message, RangedSet +from qpid.datatypes import Message, RangedSet, uuid4 from qpid.queue import Empty @@ -20,11 +20,22 @@ from qpid.queue import Empty # 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 +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"] @@ -32,10 +43,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())) #----- Read from queue -------------------------------------------- @@ -44,16 +55,17 @@ session = conn.session(str(randint(1,64*1024))) # The consumer tag identifies the client-side queue. -consumer_tag = "consumer1" -queue = session.incoming(consumer_tag) +local_queue_name = "local_queue" +queue = session.incoming(local_queue_name) -# Call message_consume() to tell the broker to deliver messages +# Call message_subscribe() to tell the broker to deliver messages # from the AMQP queue to this local client queue. The broker will -# start delivering messages as soon as message_consume() is called. +# start delivering messages as soon as credit is allocated using +# session.message_flow(). -session.message_subscribe(queue="message_queue", destination=consumer_tag) -session.message_flow(consumer_tag, 0, 0xFFFFFFFF) # Kill these? -session.message_flow(consumer_tag, 1, 0xFFFFFFFF) # Kill these? +session.message_subscribe(queue="message_queue", destination=local_queue_name) +session.message_flow(local_queue_name, session.credit_unit.message, 0xFFFFFFFF) +session.message_flow(local_queue_name, session.credit_unit.byte, 0xFFFFFFFF) # Initialize 'final' and 'content', variables used to identify the last message. @@ -67,15 +79,6 @@ while content != final: session.message_accept(RangedSet(message.id)) print content -# Messages are not removed from the queue until they are -# acknowledged. Using cumulative=True, all messages from the session -# up to and including the one identified by the delivery tag are -# acknowledged. This is more efficient, because there are fewer -# network round-trips. - -#message.complete(cumulative=True) -# ? Is there an equivakent to the above in the new API ? - #----- Cleanup ------------------------------------------------ # Clean up before exiting so there are no open threads. diff --git a/qpid/python/examples/direct/direct_producer.py b/qpid/python/examples/direct/direct_producer.py index 7c4e30d96e..8f6a91ba18 100755 --- a/qpid/python/examples/direct/direct_producer.py +++ b/qpid/python/examples/direct/direct_producer.py @@ -9,21 +9,33 @@ 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 uuid4 from qpid.queue import Empty + #----- 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 +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 +43,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,9 +54,9 @@ session = conn.session(str(randint(1,64*1024))) props = session.delivery_properties(routing_key="routing_key") for i in range(10): - session.message_transfer("amq.direct",None, None, Message(props,"message " + str(i))) + session.message_transfer(destination="amq.direct", message=Message(props,"message " + str(i))) -session.message_transfer("amq.direct",None,None, Message(props,"That's all, folks!")) +session.message_transfer(destination="amq.direct", message=Message(props,"That's all, folks!")) #----- Cleanup -------------------------------------------- diff --git a/qpid/python/examples/direct/listener.py b/qpid/python/examples/direct/listener.py index aa60b1c501..c18ef47fb7 100755 --- a/qpid/python/examples/direct/listener.py +++ b/qpid/python/examples/direct/listener.py @@ -7,14 +7,18 @@ as a message listener. """ +# Common includes + 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, RangedSet -from qpid.queue import Empty +from qpid.datatypes import Message, RangedSet, uuid4 +from qpid.queue import Empty + +# Includes specific to this example + from time import sleep @@ -33,23 +37,26 @@ class Receiver: if content == "That's all, folks!": self.finalReceived = True - # Messages are not removed from the queue until they are - # acknowledged. Using cumulative=True, all messages from the session - # up to and including the one identified by the delivery tag are - # acknowledged. This is more efficient, because there are fewer - # network round-trips. - #message.complete(cumulative=True) - - #----- 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 +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"] @@ -57,33 +64,33 @@ 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())) #----- Read from queue -------------------------------------------- # Now let's create a local client queue and tell it to read # incoming messages. -# The consumer tag identifies the client-side queue. +# The local_queue_name identifies the client-side queue. -consumer_tag = "consumer1" -queue = session.incoming(consumer_tag) +local_queue_name = "local_queue" +queue = session.incoming(local_queue_name) # Call message_subscribe() to tell the broker to deliver messages # from the AMQP queue to this local client queue. The broker will # start delivering messages as soon as message_subscribe() is called. -session.message_subscribe(queue="message_queue", destination=consumer_tag) -session.message_flow(consumer_tag, 0, 0xFFFFFFFF) # Kill these? -session.message_flow(consumer_tag, 1, 0xFFFFFFFF) # Kill these? +session.message_subscribe(queue="message_queue", destination=local_queue_name) +session.message_flow(local_queue_name, session.credit_unit.message, 0xFFFFFFFF) +session.message_flow(local_queue_name, session.credit_unit.byte, 0xFFFFFFFF) -receiver = Receiver () +receiver = Receiver() queue.listen (receiver.Handler) -while not receiver.isFinal (): +while not receiver.isFinal() : sleep (1) diff --git a/qpid/python/examples/fanout/fanout_consumer.py b/qpid/python/examples/fanout/fanout_consumer.py index b82d8045ff..21fc5e8f16 100755 --- a/qpid/python/examples/fanout/fanout_consumer.py +++ b/qpid/python/examples/fanout/fanout_consumer.py @@ -13,61 +13,27 @@ from qpid.connection import Connection from qpid.datatypes import Message, RangedSet, uuid4 from qpid.queue import Empty -#----- Functions ------------------------------------------- - -def dump_queue(session, queue_name): - - print "Messages queue: " + queue_name - - consumer_tag = queue_name # Use the queue name as the consumer tag - need a unique tag - queue = session.incoming(queue_name) - - # Call message_subscribe() to tell the broker to deliver messages - # from the AMQP queue to a local client queue. The broker will - # start delivering messages as soon as message_subscribe() is called. - - session.message_subscribe(queue=queue_name, destination=consumer_tag) - session.message_flow(consumer_tag, 0, 0xFFFFFFFF) - session.message_flow(consumer_tag, 1, 0xFFFFFFFF) - - print "Subscribed to queue " + queue_name - sys.stdout.flush() - - message = 0 - - while True: - try: - message = queue.get(timeout=10) - content = message.body - session.message_accept(RangedSet(message.id)) - print "Response: " + content - except Empty: - print "No more messages!" - break - except: - print "Unexpected exception!" - break - - - # Messages are not removed from the queue until they - # are acknowledged. Using cumulative=True, all messages - # in the session up to and including the one identified - # by the delivery tag are acknowledged. This is more efficient, - # because there are fewer network round-trips. - - #if message != 0: - # message.complete(cumulative=True) - - #----- 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 +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"] @@ -75,25 +41,48 @@ 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() +socket = connect(host, port) +connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection.start() +session = connection.session(str(uuid4())) + + +#----- Main Body ------------------------------------------- + +# Create a server-side queue and route messages to it. +# The server-side queue must have a unique name. Use the +# session id for that. +server_queue_name = session.name +session.queue_declare(queue=server_queue_name) +session.exchange_bind(queue=server_queue_name, exchange="amq.fanout") + +# Create a local queue to receive messages from the server-side +# queue. +local_queue_name = "local_queue" +local_queue = session.incoming(local_queue_name) + +# Call message_consume() to tell the server to deliver messages +# from the AMQP queue to this local client queue. -session_id = str(uuid4()) -session = conn.session(session_id) +session.message_subscribe(queue=server_queue_name, destination=local_queue_name) +session.message_flow(local_queue_name, session.credit_unit.message, 0xFFFFFFFF) +session.message_flow(local_queue_name, session.credit_unit.byte, 0xFFFFFFFF) -#----- Main Body -- ---------------------------------------- +print "Subscribed to queue " + server_queue_name +sys.stdout.flush() -# Make a unique queue name for my queue from the session ID. -my_queue = session_id -session.queue_declare(queue=my_queue) +# Initialize 'final' and 'content', variables used to identify the last message. +final = "That's all, folks!" # In a message body, signals the last message +content = "" # Content of the last message read -# Bind my queue to the fanout exchange. No routing key is required -# the fanout exchange copies messages unconditionally to every -# bound queue -session.exchange_bind(queue=my_queue, exchange="amq.fanout") +# Read the messages - acknowledge each one +message = None +while content != final: + message = local_queue.get(timeout=10) + content = message.body + session.message_accept(RangedSet(message.id)) + print content -# Dump the messages on the queue. -dump_queue(session, my_queue) #----- Cleanup ------------------------------------------------ diff --git a/qpid/python/examples/fanout/fanout_producer.py b/qpid/python/examples/fanout/fanout_producer.py index 1b5ea6995e..43d6a94c3d 100755 --- a/qpid/python/examples/fanout/fanout_producer.py +++ b/qpid/python/examples/fanout/fanout_producer.py @@ -8,21 +8,31 @@ 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, uuid4 from qpid.queue import Empty #----- 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 +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"] @@ -30,19 +40,22 @@ 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() +socket = connect(host, port) +connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection.start() +session = connection.session(str(uuid4())) -session = conn.session(str(randint(1,64*1024))) #----- Publish some messages ------------------------------ # Create some messages and put them on the broker. +delivery_properties = session.delivery_properties(routing_key="routing_key") + for i in range(10): - session.message_transfer("amq.fanout", None, None ,Message("message " + str(i))) + session.message_transfer(destination="amq.fanout", message=Message(delivery_properties,"message " + str(i))) -session.message_transfer("amq.fanout", None, None, Message("That's all, folks!")) +session.message_transfer(destination="amq.fanout", message=Message(delivery_properties, "That's all, folks!")) #----- Cleanup -------------------------------------------- diff --git a/qpid/python/examples/fanout/listener.py b/qpid/python/examples/fanout/listener.py index 8997c3698f..50cd06d2a5 100755 --- a/qpid/python/examples/fanout/listener.py +++ b/qpid/python/examples/fanout/listener.py @@ -8,11 +8,15 @@ import qpid import sys -from qpid.client import Client -from qpid.content import Content -from qpid.queue import Empty -from time import sleep +import os +from qpid.util import connect +from qpid.connection import Connection +from qpid.datatypes import Message, RangedSet, uuid4 +from qpid.queue import Empty + +# +from time import sleep #----- Message Receive Handler ----------------------------- class Receiver: @@ -23,57 +27,76 @@ class Receiver: return self.finalReceived def Handler (self, message): - content = message.content.body + content = message.body + session.message_accept(RangedSet(message.id)) print content if content == "That's all, folks!": self.finalReceived = True - # Messages are not removed from the queue until they are - # acknowledged. Using cumulative=True, all messages from the session - # up to and including the one identified by the delivery tag are - # acknowledged. This is more efficient, because there are fewer - # network round-trips. - message.complete(cumulative=True) - #----- 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 -amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" +host="127.0.0.1" +port=5672 user="guest" password="guest" +amqp_spec="/usr/share/amqp/amqp.0-10.xml" -# Create a client and log in to it. +# 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. -client = Client(host, port, qpid.spec.load(amqp_spec)) -client.start({"LOGIN": user, "PASSWORD": password}) +if len(sys.argv) > 1 : + host=sys.argv[1] +if len(sys.argv) > 2 : + port=int(sys.argv[2]) -session = client.session() -session.session_open() +try: + amqp_spec = os.environ["AMQP_SPEC"] +except KeyError: + amqp_spec="/usr/share/amqp/amqp.0-10.xml" + +# Create a connection. +socket = connect(host, port) +connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection.start() +session = connection.session(str(uuid4())) #----- Read from queue -------------------------------------------- -# Now let's create a local client queue and tell it to read -# incoming messages. +# Create a server-side queue and route messages to it. +# The server-side queue must have a unique name. Use the +# session id for that. + +server_queue_name = session.name +session.queue_declare(queue=server_queue_name) +session.exchange_bind(queue=server_queue_name, exchange="amq.fanout") + +# Create a local queue to receive messages from the server-side +# queue. +local_queue_name = "local_queue" +local_queue = session.incoming(local_queue_name) + -# The consumer tag identifies the client-side queue. +# The local queue name identifies the client-side queue. -consumer_tag = "consumer1" -queue = client.queue(consumer_tag) +local_queue_name = "local_queue" +local_queue = session.incoming(local_queue_name) # Call message_subscribe() to tell the broker to deliver messages # from the AMQP queue to this local client queue. The broker will # start delivering messages as soon as message_subscribe() is called. -session.message_subscribe(queue="message_queue", destination=consumer_tag) -session.message_flow(consumer_tag, 0, 0xFFFFFFFF) # Kill these? -session.message_flow(consumer_tag, 1, 0xFFFFFFFF) # Kill these? +session.message_subscribe(queue=server_queue_name, destination=local_queue_name) +session.message_flow(local_queue_name, session.credit_unit.message, 0xFFFFFFFF) +session.message_flow(local_queue_name, session.credit_unit.byte, 0xFFFFFFFF) receiver = Receiver () -queue.listen (receiver.Handler) +local_queue.listen (receiver.Handler) while not receiver.isFinal (): sleep (1) @@ -84,4 +107,4 @@ while not receiver.isFinal (): # Clean up before exiting so there are no open threads. # -session.session_close() +session.close() diff --git a/qpid/python/examples/fanout/verify.in b/qpid/python/examples/fanout/verify.in index 30dfeb9e69..d4b8670de9 100644 --- a/qpid/python/examples/fanout/verify.in +++ b/qpid/python/examples/fanout/verify.in @@ -1,31 +1,27 @@ ==== fanout_producer.py.out ==== fanout_consumer.py.out | remove_uuid -Messages queue: Subscribed to queue -Response: message 0 -Response: message 1 -Response: message 2 -Response: message 3 -Response: message 4 -Response: message 5 -Response: message 6 -Response: message 7 -Response: message 8 -Response: message 9 -Response: That's all, folks! -No more messages! +message 0 +message 1 +message 2 +message 3 +message 4 +message 5 +message 6 +message 7 +message 8 +message 9 +That's all, folks! ==== fanout_consumer.pyX.out | remove_uuid -Messages queue: Subscribed to queue -Response: message 0 -Response: message 1 -Response: message 2 -Response: message 3 -Response: message 4 -Response: message 5 -Response: message 6 -Response: message 7 -Response: message 8 -Response: message 9 -Response: That's all, folks! -No more messages! +message 0 +message 1 +message 2 +message 3 +message 4 +message 5 +message 6 +message 7 +message 8 +message 9 +That's all, folks! diff --git a/qpid/python/examples/pubsub/topic_publisher.py b/qpid/python/examples/pubsub/topic_publisher.py index b79896eaf6..64e5a99924 100755 --- a/qpid/python/examples/pubsub/topic_publisher.py +++ b/qpid/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 -------------------------------------------- diff --git a/qpid/python/examples/pubsub/topic_subscriber.py b/qpid/python/examples/pubsub/topic_subscriber.py index 6908be5471..3c4a8d8d0c 100755 --- a/qpid/python/examples/pubsub/topic_subscriber.py +++ b/qpid/python/examples/pubsub/topic_subscriber.py @@ -16,20 +16,7 @@ from qpid.queue import Empty #----- Functions ------------------------------------------- -def dump_queue(queue_name): - - print "Messages queue: " + queue_name - - consumer_tag = queue_name # Use the queue name as the consumer tag - need a unique tag - queue = session.incoming(consumer_tag) - - # Call message_subscribe() to tell the broker to deliver messages - # from the AMQP queue to a local client queue. The broker will - # start delivering messages as soon as message_subscribe() is called. - - session.message_subscribe(queue=queue_name, destination=consumer_tag) - session.message_flow(consumer_tag, 0, 0xFFFFFFFF) - session.message_flow(consumer_tag, 1, 0xFFFFFFFF) +def dump_queue(queue): content = "" # Content of the last message read final = "That's all, folks!" # In a message body, signals the last message @@ -37,36 +24,48 @@ def dump_queue(queue_name): while content != final: try: - message = queue.get() + message = queue.get(timeout=10) content = message.body session.message_accept(RangedSet(message.id)) print content except Empty: - #if message != 0: - # message.complete(cumulative=True) print "No more messages!" return - # Messages are not removed from the queue until they - # are acknowledged. Using multiple=True, all messages - # in the channel up to and including the one identified - # by the delivery tag are acknowledged. This is more efficient, - # because there are fewer network round-trips. - #if message != 0: - # message.complete(cumulative=True) +def subscribe_queue(server_queue_name, local_queue_name): + print "Subscribing local queue '" + local_queue_name + "' to " + server_queue_name + "'" + + queue = session.incoming(local_queue_name) + + session.message_subscribe(queue=server_queue_name, destination=local_queue_name) + session.message_flow(local_queue_name, session.credit_unit.message, 0xFFFFFFFF) + session.message_flow(local_queue_name, session.credit_unit.byte, 0xFFFFFFFF) + + return queue #----- 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 +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"] @@ -74,19 +73,19 @@ 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_id = str(uuid4()) -session = conn.session(session_id) +socket = connect(host, port) +connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection.start() +session = connection.session(str(uuid4())) #----- Main Body -- ---------------------------------------- +# declare queues on the server -news = "news" + session_id -weather = "weather" + session_id -usa = "usa" + session_id -europe = "europe" + session_id +news = "news-" + session.name +weather = "weather-" + session.name +usa = "usa-" + session.name +europe = "europe-" + session.name session.queue_declare(queue=news, exclusive=True) session.queue_declare(queue=weather, exclusive=True) @@ -115,12 +114,31 @@ session.exchange_bind(exchange="amq.topic", queue=europe, binding_key="control") print "Queues created - please start the topic producer" sys.stdout.flush() +# Subscribe local queues to server queues + +local_news = "local_news" +local_weather = "local_weather" +local_usa = "local_usa" +local_europe = "local_europe" + +local_news_queue = subscribe_queue(news, local_news) +local_weather_queue = subscribe_queue(weather, local_weather) +local_usa_queue = subscribe_queue(usa, local_usa) +local_europe_queue = subscribe_queue(europe, local_europe) + # Call dump_queue to print messages from each queue -dump_queue(news) -dump_queue(weather) -dump_queue(usa) -dump_queue(europe) +print "Messages on 'news' queue:" +dump_queue(local_news_queue) + +print "Messages on 'weather' queue:" +dump_queue(local_weather_queue) + +print "Messages on 'usa' queue:" +dump_queue(local_usa_queue) + +print "Messages on 'europe' queue:" +dump_queue(local_europe_queue) #----- Cleanup ------------------------------------------------ diff --git a/qpid/python/examples/pubsub/verify.in b/qpid/python/examples/pubsub/verify.in index 2f6da09ec5..1b74acd832 100644 --- a/qpid/python/examples/pubsub/verify.in +++ b/qpid/python/examples/pubsub/verify.in @@ -1,51 +1,55 @@ ==== topic_publisher.py.out ==== topic_subscriber.py.out | remove_uuid | sort -message 0 -message 0 -message 0 -message 0 -message 0 -message 0 -message 0 -message 0 -message 1 -message 1 -message 1 -message 1 -message 1 -message 1 -message 1 -message 1 -message 2 -message 2 -message 2 -message 2 -message 2 -message 2 -message 2 -message 2 -message 3 -message 3 -message 3 -message 3 -message 3 -message 3 -message 3 -message 3 -message 4 -message 4 -message 4 -message 4 -message 4 -message 4 -message 4 -message 4 -Messages queue: europe -Messages queue: news -Messages queue: usa -Messages queue: weather +europe.news 0 +europe.news 0 +europe.news 1 +europe.news 1 +europe.news 2 +europe.news 2 +europe.news 3 +europe.news 3 +europe.news 4 +europe.news 4 +europe.weather 0 +europe.weather 0 +europe.weather 1 +europe.weather 1 +europe.weather 2 +europe.weather 2 +europe.weather 3 +europe.weather 3 +europe.weather 4 +europe.weather 4 +Messages on 'europe' queue: +Messages on 'news' queue: +Messages on 'usa' queue: +Messages on 'weather' queue: Queues created - please start the topic producer +Subscribing local queue 'local_europe' to europe-' +Subscribing local queue 'local_news' to news-' +Subscribing local queue 'local_usa' to usa-' +Subscribing local queue 'local_weather' to weather-' That's all, folks! That's all, folks! That's all, folks! That's all, folks! +usa.news 0 +usa.news 0 +usa.news 1 +usa.news 1 +usa.news 2 +usa.news 2 +usa.news 3 +usa.news 3 +usa.news 4 +usa.news 4 +usa.weather 0 +usa.weather 0 +usa.weather 1 +usa.weather 1 +usa.weather 2 +usa.weather 2 +usa.weather 3 +usa.weather 3 +usa.weather 4 +usa.weather 4 diff --git a/qpid/python/examples/request-response/client.py b/qpid/python/examples/request-response/client.py index 8f7d430d1b..0fcd256d49 100755 --- a/qpid/python/examples/request-response/client.py +++ b/qpid/python/examples/request-response/client.py @@ -18,18 +18,7 @@ from qpid.queue import Empty def dump_queue(queue_name): - print "Messages queue: " + queue_name - - consumer_tag = queue_name # Use the queue name as the consumer tag - need a unique tag - queue = session.incoming(consumer_tag) - - # Call message_subscribe() to tell the broker to deliver messages - # from the AMQP queue to a local client queue. The broker will - # start delivering messages as soon as message_subscribe() is called. - - session.message_subscribe(queue=queue_name, destination=consumer_tag) - session.message_flow(consumer_tag, 0, 0xFFFFFFFF) - session.message_flow(consumer_tag, 1, 0xFFFFFFFF) + print "Messages on queue: " + queue_name message = 0 @@ -47,25 +36,27 @@ def dump_queue(queue_name): break - # Messages are not removed from the queue until they - # are acknowledged. Using cumulative=True, all messages - # in the session up to and including the one identified - # by the delivery tag are acknowledged. This is more efficient, - # because there are fewer network round-trips. - - #if message != 0: - # message.complete(cumulative=True) - - #----- 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 +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"] @@ -73,11 +64,11 @@ 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() +socket = connect(host, port) +connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection.start() +session = connection.session(str(uuid4())) -session_id = str(uuid4()) -session = conn.session(session_id) #----- Main Body -- ---------------------------------------- @@ -85,9 +76,23 @@ session = conn.session(session_id) # same string as the name of the queue and the name of the routing # key. -replyTo = "ReplyTo:" + session_id -session.queue_declare(queue=replyTo, exclusive=True) -session.exchange_bind(exchange="amq.direct", queue=replyTo, binding_key=replyTo) +reply_to = "reply_to:" + session.name +session.queue_declare(queue=reply_to, exclusive=True) +session.exchange_bind(exchange="amq.direct", queue=reply_to, binding_key=reply_to) + +# Create a local queue and subscribe it to the response queue + +local_queue_name = "local_queue" +queue = session.incoming(local_queue_name) + +# Call message_subscribe() to tell the broker to deliver messages from +# the server's reply_to queue to our local client queue. The server +# will start delivering messages as soon as message credit is +# available. + +session.message_subscribe(queue=reply_to, destination=local_queue_name) +session.message_flow(local_queue_name, session.credit_unit.message, 0xFFFFFFFF) +session.message_flow(local_queue_name, session.credit_unit.byte, 0xFFFFFFFF) # Send some messages to the server's request queue @@ -96,16 +101,20 @@ lines = ["Twas brilling, and the slithy toves", "All mimsy were the borogroves,", "And the mome raths outgrabe."] -for ln in lines: - print "Request: " + ln - mp = session.message_properties() - mp.reply_to = session.reply_to("amq.direct", replyTo) - dp = session.delivery_properties(routing_key="request") - session.message_transfer("amq.direct", None, None, Message(mp,dp,ln)) +# We will use the same reply_to and routing key +# for each message + +message_properties = session.message_properties() +message_properties.reply_to = session.reply_to("amq.direct", reply_to) +delivery_properties = session.delivery_properties(routing_key="request") + +for line in lines: + print "Request: " + line + session.message_transfer(destination="amq.direct", message=Message(message_properties, delivery_properties, line)) -# Now see what messages the server sent to our replyTo queue +# Now see what messages the server sent to our reply_to queue -dump_queue(replyTo) +dump_queue(reply_to) #----- Cleanup ------------------------------------------------ diff --git a/qpid/python/examples/request-response/server.py b/qpid/python/examples/request-response/server.py index 4377571248..7b182723b9 100755 --- a/qpid/python/examples/request-response/server.py +++ b/qpid/python/examples/request-response/server.py @@ -4,6 +4,7 @@ Server for a client/server example """ + import qpid import sys import os @@ -22,31 +23,42 @@ def respond(session, request): message_properties = request.get("message_properties") reply_to = message_properties.reply_to if reply_to == None: - raise Exception("reply to property needs to be there") - - props = session.delivery_properties(routing_key=reply_to["routing_key"]) - session.message_transfer(reply_to["exchange"],None, None, Message(props,request.body.upper())) + raise Exception("This message is missing the 'reply_to' property, which is required") + + props = session.delivery_properties(routing_key=reply_to["routing_key"]) + session.message_transfer(destination=reply_to["exchange"], message=Message(props,request.body.upper())) #----- 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 + +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"] 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_id = str(uuid4()) -session = conn.session(session_id) +socket = connect(host, port) +connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection.start() +session = connection.session(str(uuid4())) #----- Main Body -- ---------------------------------------- @@ -55,11 +67,11 @@ session = conn.session(session_id) session.queue_declare(queue="request", exclusive=True) session.exchange_bind(exchange="amq.direct", queue="request", binding_key="request") -dest = "request_destination" +local_queue_name = "local_queue" -session.message_subscribe(queue="request", destination=dest) -session.message_flow(dest, 0, 0xFFFFFFFF) -session.message_flow(dest, 1, 0xFFFFFFFF) +session.message_subscribe(queue="request", destination=local_queue_name) +session.message_flow(local_queue_name, session.credit_unit.message, 0xFFFFFFFF) +session.message_flow(local_queue_name, session.credit_unit.byte, 0xFFFFFFFF) # Remind the user to start the client program @@ -70,7 +82,7 @@ sys.stdout.flush() # Respond to each request -queue = session.incoming(dest) +queue = session.incoming(local_queue_name) # If we get a message, send it back to the user (as indicated in the # ReplyTo property) diff --git a/qpid/python/examples/request-response/verify.in b/qpid/python/examples/request-response/verify.in index 8d7f732ec8..6c24366722 100644 --- a/qpid/python/examples/request-response/verify.in +++ b/qpid/python/examples/request-response/verify.in @@ -3,7 +3,7 @@ Request: Twas brilling, and the slithy toves Request: Did gyre and gimble in the wabe. Request: All mimsy were the borogroves, Request: And the mome raths outgrabe. -Messages queue: ReplyTo: +Messages on queue: reply_to: Response: TWAS BRILLING, AND THE SLITHY TOVES Response: DID GYRE AND GIMBLE IN THE WABE. Response: ALL MIMSY WERE THE BOROGROVES, -- cgit v1.2.1 From 1b092b72dd110848a9dce856fede4f4a0af83331 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Tue, 13 May 2008 18:39:11 +0000 Subject: Fix typo in examples. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@655965 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/request-response/client.py | 2 +- qpid/python/examples/request-response/verify.in | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/request-response/client.py b/qpid/python/examples/request-response/client.py index 0fcd256d49..8ab1149901 100755 --- a/qpid/python/examples/request-response/client.py +++ b/qpid/python/examples/request-response/client.py @@ -96,7 +96,7 @@ session.message_flow(local_queue_name, session.credit_unit.byte, 0xFFFFFFFF) # Send some messages to the server's request queue -lines = ["Twas brilling, and the slithy toves", +lines = ["Twas brillig, and the slithy toves", "Did gyre and gimble in the wabe.", "All mimsy were the borogroves,", "And the mome raths outgrabe."] diff --git a/qpid/python/examples/request-response/verify.in b/qpid/python/examples/request-response/verify.in index 6c24366722..4c31128975 100644 --- a/qpid/python/examples/request-response/verify.in +++ b/qpid/python/examples/request-response/verify.in @@ -1,10 +1,10 @@ ==== client.py.out | remove_uuid -Request: Twas brilling, and the slithy toves +Request: Twas brillig, and the slithy toves Request: Did gyre and gimble in the wabe. Request: All mimsy were the borogroves, Request: And the mome raths outgrabe. Messages on queue: reply_to: -Response: TWAS BRILLING, AND THE SLITHY TOVES +Response: TWAS BRILLIG, AND THE SLITHY TOVES Response: DID GYRE AND GIMBLE IN THE WABE. Response: ALL MIMSY WERE THE BOROGROVES, Response: AND THE MOME RATHS OUTGRABE. -- cgit v1.2.1 From 4bed8993507c1a9e89a7cc04547faf409356e347 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Tue, 13 May 2008 20:38:21 +0000 Subject: From Jonathan Robie: https://issues.apache.org/jira/browse/QPID-1056: Python examples for the xml exchange. https://issues.apache.org/jira/browse/QPID-1057 Fixes to the XmlExchange.cpp that prevent it from crashing the broker when used with python clients that don't send application header properties git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@656005 13f79535-47bb-0310-9956-ffa450edef68 --- .../python/examples/xml-exchange/declare_queues.py | 82 ++++++++++++++++++ qpid/python/examples/xml-exchange/listener.py | 98 ++++++++++++++++++++++ qpid/python/examples/xml-exchange/verify | 3 + qpid/python/examples/xml-exchange/verify.in | 14 ++++ qpid/python/examples/xml-exchange/xml_consumer.py | 89 ++++++++++++++++++++ qpid/python/examples/xml-exchange/xml_producer.py | 84 +++++++++++++++++++ 6 files changed, 370 insertions(+) create mode 100644 qpid/python/examples/xml-exchange/declare_queues.py create mode 100644 qpid/python/examples/xml-exchange/listener.py create mode 100644 qpid/python/examples/xml-exchange/verify create mode 100644 qpid/python/examples/xml-exchange/verify.in create mode 100644 qpid/python/examples/xml-exchange/xml_consumer.py create mode 100644 qpid/python/examples/xml-exchange/xml_producer.py (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/xml-exchange/declare_queues.py b/qpid/python/examples/xml-exchange/declare_queues.py new file mode 100644 index 0000000000..d3bf4d359e --- /dev/null +++ b/qpid/python/examples/xml-exchange/declare_queues.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python +""" + declare_queues.py + + Creates and binds a queue on an AMQP direct exchange. + + All messages using the routing key "routing_key" are + sent to the queue named "message_queue". +""" + +import qpid +import sys +import os +from qpid.util import connect +from qpid.connection import Connection +from qpid.datatypes import Message, RangedSet, uuid4 +from qpid.queue import Empty + +#----- Initialization ----------------------------------- + + +# Set parameters for login + +host="127.0.0.1" +port=5672 +user="guest" +password="guest" +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"] +except KeyError: + amqp_spec="/usr/share/amqp/amqp.0-10.xml" + +# Create a connection. +socket = connect(host, port) +connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection.start() +session = connection.session(str(uuid4())) + +#----- Create a queue ------------------------------------- + +# queue_declare() creates an AMQP queue, which is held +# on the broker. Published messages are sent to the AMQP queue, +# from which messages are delivered to consumers. +# +# queue_bind() determines which messages are routed to a queue. +# Route all messages with the routing key "routing_key" to +# the AMQP queue named "message_queue". + +session.exchange_declare(exchange="xml", type="xml") +session.queue_declare(queue="message_queue") + +binding = {} +binding["xquery"] = """ + let $w := ./weather + return $w/station = 'Raleigh-Durham International Airport (KRDU)' + and $w/temperature_f > 50 + and $w/temperature_f - $w/dewpoint > 5 + and $w/wind_speed_mph > 7 + and $w/wind_speed_mph < 20 """ + + +session.exchange_bind(exchange="xml", queue="message_queue", binding_key="weather", arguments=binding) + + +#----- Cleanup --------------------------------------------- + +session.close() + + diff --git a/qpid/python/examples/xml-exchange/listener.py b/qpid/python/examples/xml-exchange/listener.py new file mode 100644 index 0000000000..cdc00a7015 --- /dev/null +++ b/qpid/python/examples/xml-exchange/listener.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python +""" + listener.py + + This AMQP client reads messages from a message + queue named "message_queue". It is implemented + as a message listener. +""" + + +import qpid +import sys +import os +from qpid.util import connect +from qpid.connection import Connection +from qpid.datatypes import Message, RangedSet, uuid4 +from qpid.queue import Empty + +# + +from time import sleep + + +#----- Message Receive Handler ----------------------------- +class Receiver: + def __init__ (self): + self.finalReceived = False + + def isFinal (self): + return self.finalReceived + + def Handler (self, message): + content = message.body + session.message_accept(RangedSet(message.id)) + print content + +#----- Initialization -------------------------------------- + +# Set parameters for login + +host="127.0.0.1" +port=5672 +user="guest" +password="guest" +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"] +except KeyError: + amqp_spec="/usr/share/amqp/amqp.0-10.xml" + +# Create a connection. +socket = connect(host, port) +connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection.start() +session = connection.session(str(uuid4())) + +#----- Read from queue -------------------------------------------- + +# Now let's create a local client queue and tell it to read +# incoming messages. + +# The consumer tag identifies the client-side queue. + +local_queue_name = "local_queue" +local_queue = session.incoming(local_queue_name) + +# Call message_subscribe() to tell the broker to deliver messages +# from the AMQP queue to this local client queue. The broker will +# start delivering messages as soon as message_subscribe() is called. + +session.message_subscribe(queue="message_queue", destination=local_queue_name) +session.message_flow(local_queue_name, session.credit_unit.message, 0xFFFFFFFF) +session.message_flow(local_queue_name, session.credit_unit.byte, 0xFFFFFFFF) + +receiver = Receiver () +local_queue.listen (receiver.Handler) + +sleep (10) + + +#----- Cleanup ------------------------------------------------ + +# Clean up before exiting so there are no open threads. +# + +session.close() diff --git a/qpid/python/examples/xml-exchange/verify b/qpid/python/examples/xml-exchange/verify new file mode 100644 index 0000000000..01d81a18a1 --- /dev/null +++ b/qpid/python/examples/xml-exchange/verify @@ -0,0 +1,3 @@ +# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify +clients ./declare_queues.py ./direct_producer.py ./direct_consumer.py +outputs ./declare_queues.py.out ./direct_producer.py.out ./direct_consumer.py.out diff --git a/qpid/python/examples/xml-exchange/verify.in b/qpid/python/examples/xml-exchange/verify.in new file mode 100644 index 0000000000..5e691619d9 --- /dev/null +++ b/qpid/python/examples/xml-exchange/verify.in @@ -0,0 +1,14 @@ +==== declare_queues.py.out +==== direct_producer.py.out +==== direct_consumer.py.out +message 0 +message 1 +message 2 +message 3 +message 4 +message 5 +message 6 +message 7 +message 8 +message 9 +That's all, folks! diff --git a/qpid/python/examples/xml-exchange/xml_consumer.py b/qpid/python/examples/xml-exchange/xml_consumer.py new file mode 100644 index 0000000000..c210a4342c --- /dev/null +++ b/qpid/python/examples/xml-exchange/xml_consumer.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python +""" + direct_consumer.py + + This AMQP client reads messages from a message + queue named "message_queue". +""" + +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, RangedSet, uuid4 +from qpid.queue import Empty + + +#----- Initialization -------------------------------------- + +# Set parameters for login + +host="127.0.0.1" +port=5672 +user="guest" +password="guest" +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"] +except KeyError: + amqp_spec="/usr/share/amqp/amqp.0-10.xml" + +# Create a connection. +socket = connect(host, port) +connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection.start() +session = connection.session(str(uuid4())) + + +#----- Read from queue -------------------------------------------- + +# Now let's create a local client queue and tell it to read +# incoming messages. + +# The consumer tag identifies the client-side queue. + +local_queue_name = "local_queue" +local_queue = session.incoming(local_queue_name) + +# Call message_consume() to tell the broker to deliver messages +# from the AMQP queue to this local client queue. The broker will +# start delivering messages as soon as message_consume() is called. + +session.message_subscribe(queue="message_queue", destination=local_queue_name) +session.message_flow(local_queue_name, session.credit_unit.message, 0xFFFFFFFF) +session.message_flow(local_queue_name, session.credit_unit.byte, 0xFFFFFFFF) + +# Initialize 'final' and 'content', variables used to identify the last message. + +message = None +while True: + try: + message = local_queue.get(timeout=10) + session.message_accept(RangedSet(message.id)) + content = message.body + print content + except Empty: + print "No more messages!" + break + + +#----- Cleanup ------------------------------------------------ + +# Clean up before exiting so there are no open threads. +# + +session.close() diff --git a/qpid/python/examples/xml-exchange/xml_producer.py b/qpid/python/examples/xml-exchange/xml_producer.py new file mode 100644 index 0000000000..9e609ed132 --- /dev/null +++ b/qpid/python/examples/xml-exchange/xml_producer.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python +""" + xml_producer.py + + Publishes messages to an XML exchange, using + the routing key "weather" +""" + + +import qpid +import sys +import os +from qpid.util import connect +from qpid.connection import Connection +from qpid.datatypes import Message, RangedSet, uuid4 +from qpid.queue import Empty + +#----- Functions ---------------------------------------- + +# Data for weather reports + +station = ("Raleigh-Durham International Airport (KRDU)", + "New Bern, Craven County Regional Airport (KEWN)", + "Boone, Watauga County Hospital Heliport (KTNB)", + "Hatteras, Mitchell Field (KHSE)") +wind_speed_mph = ( 0, 2, 5, 10, 16, 22, 28, 35, 42, 51, 61, 70, 80 ) +temperature_f = ( 30, 40, 50, 60, 70, 80, 90, 100 ) +dewpoint = ( 35, 40, 45, 50 ) + +def pick_one(list, i): + return str( list [ i % len(list)] ) + +def report(i): + return "" + "" + pick_one(station,i)+ "" + "" + pick_one(wind_speed_mph,i) + "" + "" + pick_one(temperature_f,i) + "" + "" + pick_one(dewpoint,i) + "" + "" + + +#----- Initialization ----------------------------------- + +# Set parameters for login + +host="127.0.0.1" +port=5672 +user="guest" +password="guest" +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"] +except KeyError: + amqp_spec="/usr/share/amqp/amqp.0-10.xml" + +# Create a connection. +socket = connect(host, port) +connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection.start() +session = connection.session(str(uuid4())) + +#----- Publish some messages ------------------------------ + +# Create some messages and put them on the broker. + +props = session.delivery_properties(routing_key="weather") + +for i in range(10): + print report(i) + session.message_transfer(destination="xml", message=Message(props, report(i))) + + +#----- Cleanup -------------------------------------------- + +# Clean up before exiting so there are no open threads. + +session.close() -- cgit v1.2.1 From 0862b2ed103b79bfb966c23bd1098ef411c3c5bf Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Wed, 14 May 2008 12:56:09 +0000 Subject: Fixed python/examples/xml-exchange verify script. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@656255 13f79535-47bb-0310-9956-ffa450edef68 --- .../python/examples/xml-exchange/declare_queues.py | 0 qpid/python/examples/xml-exchange/listener.py | 0 qpid/python/examples/xml-exchange/verify | 4 ++-- qpid/python/examples/xml-exchange/verify.in | 27 +++++++++++----------- qpid/python/examples/xml-exchange/xml_consumer.py | 0 qpid/python/examples/xml-exchange/xml_producer.py | 0 6 files changed, 16 insertions(+), 15 deletions(-) mode change 100644 => 100755 qpid/python/examples/xml-exchange/declare_queues.py mode change 100644 => 100755 qpid/python/examples/xml-exchange/listener.py mode change 100644 => 100755 qpid/python/examples/xml-exchange/xml_consumer.py mode change 100644 => 100755 qpid/python/examples/xml-exchange/xml_producer.py (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/xml-exchange/declare_queues.py b/qpid/python/examples/xml-exchange/declare_queues.py old mode 100644 new mode 100755 diff --git a/qpid/python/examples/xml-exchange/listener.py b/qpid/python/examples/xml-exchange/listener.py old mode 100644 new mode 100755 diff --git a/qpid/python/examples/xml-exchange/verify b/qpid/python/examples/xml-exchange/verify index 01d81a18a1..bf05463f1d 100644 --- a/qpid/python/examples/xml-exchange/verify +++ b/qpid/python/examples/xml-exchange/verify @@ -1,3 +1,3 @@ # See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -clients ./declare_queues.py ./direct_producer.py ./direct_consumer.py -outputs ./declare_queues.py.out ./direct_producer.py.out ./direct_consumer.py.out +clients ./declare_queues.py ./xml_producer.py ./xml_consumer.py +outputs ./declare_queues.py.out ./xml_producer.py.out ./xml_consumer.py.out diff --git a/qpid/python/examples/xml-exchange/verify.in b/qpid/python/examples/xml-exchange/verify.in index 5e691619d9..e5b9909408 100644 --- a/qpid/python/examples/xml-exchange/verify.in +++ b/qpid/python/examples/xml-exchange/verify.in @@ -1,14 +1,15 @@ ==== declare_queues.py.out -==== direct_producer.py.out -==== direct_consumer.py.out -message 0 -message 1 -message 2 -message 3 -message 4 -message 5 -message 6 -message 7 -message 8 -message 9 -That's all, folks! +==== xml_producer.py.out +Raleigh-Durham International Airport (KRDU)03035 +New Bern, Craven County Regional Airport (KEWN)24040 +Boone, Watauga County Hospital Heliport (KTNB)55045 +Hatteras, Mitchell Field (KHSE)106050 +Raleigh-Durham International Airport (KRDU)167035 +New Bern, Craven County Regional Airport (KEWN)228040 +Boone, Watauga County Hospital Heliport (KTNB)289045 +Hatteras, Mitchell Field (KHSE)3510050 +Raleigh-Durham International Airport (KRDU)423035 +New Bern, Craven County Regional Airport (KEWN)514040 +==== xml_consumer.py.out +Raleigh-Durham International Airport (KRDU)167035 +No more messages! diff --git a/qpid/python/examples/xml-exchange/xml_consumer.py b/qpid/python/examples/xml-exchange/xml_consumer.py old mode 100644 new mode 100755 diff --git a/qpid/python/examples/xml-exchange/xml_producer.py b/qpid/python/examples/xml-exchange/xml_producer.py old mode 100644 new mode 100755 -- cgit v1.2.1 From ca3bc30a4ff5fbd2504b2868eea60e647b16b2d8 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Thu, 15 May 2008 21:34:10 +0000 Subject: - Enable python tets and examples in make rpmbuild. - Remove hard-coded amqp.xml paths from python examples. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@656853 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/direct/declare_queues.py | 8 +------- qpid/python/examples/direct/direct_consumer.py | 8 +------- qpid/python/examples/direct/direct_producer.py | 8 +------- qpid/python/examples/direct/listener.py | 8 +------- qpid/python/examples/fanout/fanout_consumer.py | 8 +------- qpid/python/examples/fanout/fanout_producer.py | 8 +------- qpid/python/examples/fanout/listener.py | 8 +------- qpid/python/examples/pubsub/topic_publisher.py | 8 +------- qpid/python/examples/pubsub/topic_subscriber.py | 8 +------- qpid/python/examples/request-response/client.py | 8 +------- qpid/python/examples/request-response/server.py | 8 +------- qpid/python/examples/xml-exchange/declare_queues.py | 8 +------- qpid/python/examples/xml-exchange/listener.py | 8 +------- qpid/python/examples/xml-exchange/xml_consumer.py | 8 +------- qpid/python/examples/xml-exchange/xml_producer.py | 8 +------- 15 files changed, 15 insertions(+), 105 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/direct/declare_queues.py b/qpid/python/examples/direct/declare_queues.py index deea0a3ccc..ce19a91a60 100755 --- a/qpid/python/examples/direct/declare_queues.py +++ b/qpid/python/examples/direct/declare_queues.py @@ -26,7 +26,6 @@ host="127.0.0.1" port=5672 user="guest" password="guest" -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) @@ -39,14 +38,9 @@ if len(sys.argv) > 1 : if len(sys.argv) > 2 : port=int(sys.argv[2]) -try: - amqp_spec = os.environ["AMQP_SPEC"] -except KeyError: - amqp_spec="/usr/share/amqp/amqp.0-10.xml" - # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection = Connection (sock=socket) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/direct/direct_consumer.py b/qpid/python/examples/direct/direct_consumer.py index f2018bbbb8..0e629b476a 100755 --- a/qpid/python/examples/direct/direct_consumer.py +++ b/qpid/python/examples/direct/direct_consumer.py @@ -24,7 +24,6 @@ host="127.0.0.1" port=5672 user="guest" password="guest" -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) @@ -37,14 +36,9 @@ if len(sys.argv) > 1 : if len(sys.argv) > 2 : port=int(sys.argv[2]) -try: - amqp_spec = os.environ["AMQP_SPEC"] -except KeyError: - amqp_spec="/usr/share/amqp/amqp.0-10.xml" - # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection = Connection (sock=socket) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/direct/direct_producer.py b/qpid/python/examples/direct/direct_producer.py index 8f6a91ba18..bdc668b3c4 100755 --- a/qpid/python/examples/direct/direct_producer.py +++ b/qpid/python/examples/direct/direct_producer.py @@ -24,7 +24,6 @@ host="127.0.0.1" port=5672 user="guest" password="guest" -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) @@ -37,14 +36,9 @@ if len(sys.argv) > 1 : if len(sys.argv) > 2 : port=int(sys.argv[2]) -try: - amqp_spec = os.environ["AMQP_SPEC"] -except KeyError: - amqp_spec="/usr/share/amqp/amqp.0-10.xml" - # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection = Connection (sock=socket) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/direct/listener.py b/qpid/python/examples/direct/listener.py index c18ef47fb7..ee13aae75b 100755 --- a/qpid/python/examples/direct/listener.py +++ b/qpid/python/examples/direct/listener.py @@ -45,7 +45,6 @@ host="127.0.0.1" port=5672 user="guest" password="guest" -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) @@ -58,14 +57,9 @@ if len(sys.argv) > 1 : if len(sys.argv) > 2 : port=int(sys.argv[2]) -try: - amqp_spec = os.environ["AMQP_SPEC"] -except KeyError: - amqp_spec="/usr/share/amqp/amqp.0-10.xml" - # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection = Connection (sock=socket) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/fanout/fanout_consumer.py b/qpid/python/examples/fanout/fanout_consumer.py index 21fc5e8f16..15452390a0 100755 --- a/qpid/python/examples/fanout/fanout_consumer.py +++ b/qpid/python/examples/fanout/fanout_consumer.py @@ -22,7 +22,6 @@ host="127.0.0.1" port=5672 user="guest" password="guest" -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) @@ -35,14 +34,9 @@ if len(sys.argv) > 1 : if len(sys.argv) > 2 : port=int(sys.argv[2]) -try: - amqp_spec = os.environ["AMQP_SPEC"] -except KeyError: - amqp_spec="/usr/share/amqp/amqp.0-10.xml" - # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection = Connection (sock=socket) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/fanout/fanout_producer.py b/qpid/python/examples/fanout/fanout_producer.py index 43d6a94c3d..f5b589c861 100755 --- a/qpid/python/examples/fanout/fanout_producer.py +++ b/qpid/python/examples/fanout/fanout_producer.py @@ -21,7 +21,6 @@ host="127.0.0.1" port=5672 user="guest" password="guest" -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) @@ -34,14 +33,9 @@ if len(sys.argv) > 1 : if len(sys.argv) > 2 : port=int(sys.argv[2]) -try: - amqp_spec = os.environ["AMQP_SPEC"] -except KeyError: - amqp_spec="/usr/share/amqp/amqp.0-10.xml" - # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection = Connection (sock=socket) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/fanout/listener.py b/qpid/python/examples/fanout/listener.py index 50cd06d2a5..56acd50e10 100755 --- a/qpid/python/examples/fanout/listener.py +++ b/qpid/python/examples/fanout/listener.py @@ -42,7 +42,6 @@ host="127.0.0.1" port=5672 user="guest" password="guest" -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) @@ -55,14 +54,9 @@ if len(sys.argv) > 1 : if len(sys.argv) > 2 : port=int(sys.argv[2]) -try: - amqp_spec = os.environ["AMQP_SPEC"] -except KeyError: - amqp_spec="/usr/share/amqp/amqp.0-10.xml" - # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection = Connection (sock=socket) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/pubsub/topic_publisher.py b/qpid/python/examples/pubsub/topic_publisher.py index 64e5a99924..fb817c15f4 100755 --- a/qpid/python/examples/pubsub/topic_publisher.py +++ b/qpid/python/examples/pubsub/topic_publisher.py @@ -30,7 +30,6 @@ host="127.0.0.1" port=5672 user="guest" password="guest" -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) @@ -43,14 +42,9 @@ if len(sys.argv) > 1 : if len(sys.argv) > 2 : port=int(sys.argv[2]) -try: - amqp_spec = os.environ["AMQP_SPEC"] -except KeyError: - amqp_spec="/usr/share/amqp/amqp.0-10.xml" - # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection = Connection (sock=socket) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/pubsub/topic_subscriber.py b/qpid/python/examples/pubsub/topic_subscriber.py index 3c4a8d8d0c..a4210c83ef 100755 --- a/qpid/python/examples/pubsub/topic_subscriber.py +++ b/qpid/python/examples/pubsub/topic_subscriber.py @@ -54,7 +54,6 @@ host="127.0.0.1" port=5672 user="guest" password="guest" -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) @@ -67,14 +66,9 @@ if len(sys.argv) > 1 : if len(sys.argv) > 2 : port=int(sys.argv[2]) -try: - amqp_spec = os.environ["AMQP_SPEC"] -except KeyError: - amqp_spec="/usr/share/amqp/amqp.0-10.xml" - # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection = Connection (sock=socket) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/request-response/client.py b/qpid/python/examples/request-response/client.py index 8ab1149901..7bb4ee3462 100755 --- a/qpid/python/examples/request-response/client.py +++ b/qpid/python/examples/request-response/client.py @@ -45,7 +45,6 @@ host="127.0.0.1" port=5672 user="guest" password="guest" -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) @@ -58,14 +57,9 @@ if len(sys.argv) > 1 : if len(sys.argv) > 2 : port=int(sys.argv[2]) -try: - amqp_spec = os.environ["AMQP_SPEC"] -except KeyError: - amqp_spec="/usr/share/amqp/amqp.0-10.xml" - # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection = Connection (sock=socket) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/request-response/server.py b/qpid/python/examples/request-response/server.py index 7b182723b9..dbe4b88208 100755 --- a/qpid/python/examples/request-response/server.py +++ b/qpid/python/examples/request-response/server.py @@ -37,7 +37,6 @@ host="127.0.0.1" port=5672 user="guest" password="guest" -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) @@ -50,13 +49,8 @@ if len(sys.argv) > 1 : if len(sys.argv) > 2 : port=int(sys.argv[2]) -try: - amqp_spec = os.environ["AMQP_SPEC"] -except KeyError: - amqp_spec="/usr/share/amqp/amqp.0-10.xml" - socket = connect(host, port) -connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection = Connection (sock=socket) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/xml-exchange/declare_queues.py b/qpid/python/examples/xml-exchange/declare_queues.py index d3bf4d359e..8985c20cab 100755 --- a/qpid/python/examples/xml-exchange/declare_queues.py +++ b/qpid/python/examples/xml-exchange/declare_queues.py @@ -25,7 +25,6 @@ host="127.0.0.1" port=5672 user="guest" password="guest" -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) @@ -38,14 +37,9 @@ if len(sys.argv) > 1 : if len(sys.argv) > 2 : port=int(sys.argv[2]) -try: - amqp_spec = os.environ["AMQP_SPEC"] -except KeyError: - amqp_spec="/usr/share/amqp/amqp.0-10.xml" - # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection = Connection (sock=socket) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/xml-exchange/listener.py b/qpid/python/examples/xml-exchange/listener.py index cdc00a7015..f2f9105091 100755 --- a/qpid/python/examples/xml-exchange/listener.py +++ b/qpid/python/examples/xml-exchange/listener.py @@ -42,7 +42,6 @@ host="127.0.0.1" port=5672 user="guest" password="guest" -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) @@ -55,14 +54,9 @@ if len(sys.argv) > 1 : if len(sys.argv) > 2 : port=int(sys.argv[2]) -try: - amqp_spec = os.environ["AMQP_SPEC"] -except KeyError: - amqp_spec="/usr/share/amqp/amqp.0-10.xml" - # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection = Connection (sock=socket) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/xml-exchange/xml_consumer.py b/qpid/python/examples/xml-exchange/xml_consumer.py index c210a4342c..047faec668 100755 --- a/qpid/python/examples/xml-exchange/xml_consumer.py +++ b/qpid/python/examples/xml-exchange/xml_consumer.py @@ -24,7 +24,6 @@ host="127.0.0.1" port=5672 user="guest" password="guest" -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) @@ -37,14 +36,9 @@ if len(sys.argv) > 1 : if len(sys.argv) > 2 : port=int(sys.argv[2]) -try: - amqp_spec = os.environ["AMQP_SPEC"] -except KeyError: - amqp_spec="/usr/share/amqp/amqp.0-10.xml" - # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection = Connection (sock=socket) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/xml-exchange/xml_producer.py b/qpid/python/examples/xml-exchange/xml_producer.py index 9e609ed132..435045b0fa 100755 --- a/qpid/python/examples/xml-exchange/xml_producer.py +++ b/qpid/python/examples/xml-exchange/xml_producer.py @@ -42,7 +42,6 @@ host="127.0.0.1" port=5672 user="guest" password="guest" -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) @@ -55,14 +54,9 @@ if len(sys.argv) > 1 : if len(sys.argv) > 2 : port=int(sys.argv[2]) -try: - amqp_spec = os.environ["AMQP_SPEC"] -except KeyError: - amqp_spec="/usr/share/amqp/amqp.0-10.xml" - # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec)) +connection = Connection (sock=socket) connection.start() session = connection.session(str(uuid4())) -- cgit v1.2.1 From 6759e54c226d6dc779afd034078c73bc3bf23093 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Thu, 15 May 2008 21:46:14 +0000 Subject: - Remove redundant comments about AMQP_SPEC git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@656859 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/direct/declare_queues.py | 4 ---- qpid/python/examples/direct/direct_consumer.py | 4 ---- qpid/python/examples/direct/direct_producer.py | 4 ---- qpid/python/examples/direct/listener.py | 4 ---- qpid/python/examples/fanout/fanout_consumer.py | 4 ---- qpid/python/examples/fanout/fanout_producer.py | 4 ---- qpid/python/examples/fanout/listener.py | 4 ---- qpid/python/examples/pubsub/topic_publisher.py | 4 ---- qpid/python/examples/pubsub/topic_subscriber.py | 4 ---- qpid/python/examples/request-response/client.py | 4 ---- qpid/python/examples/request-response/server.py | 4 ---- qpid/python/examples/xml-exchange/declare_queues.py | 4 ---- qpid/python/examples/xml-exchange/listener.py | 4 ---- qpid/python/examples/xml-exchange/xml_consumer.py | 4 ---- qpid/python/examples/xml-exchange/xml_producer.py | 4 ---- 15 files changed, 60 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/direct/declare_queues.py b/qpid/python/examples/direct/declare_queues.py index ce19a91a60..f0c34fa8c9 100755 --- a/qpid/python/examples/direct/declare_queues.py +++ b/qpid/python/examples/direct/declare_queues.py @@ -29,10 +29,6 @@ password="guest" # 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 : diff --git a/qpid/python/examples/direct/direct_consumer.py b/qpid/python/examples/direct/direct_consumer.py index 0e629b476a..e421a417c1 100755 --- a/qpid/python/examples/direct/direct_consumer.py +++ b/qpid/python/examples/direct/direct_consumer.py @@ -27,10 +27,6 @@ password="guest" # 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 : diff --git a/qpid/python/examples/direct/direct_producer.py b/qpid/python/examples/direct/direct_producer.py index bdc668b3c4..870ce66e78 100755 --- a/qpid/python/examples/direct/direct_producer.py +++ b/qpid/python/examples/direct/direct_producer.py @@ -27,10 +27,6 @@ password="guest" # 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 : diff --git a/qpid/python/examples/direct/listener.py b/qpid/python/examples/direct/listener.py index ee13aae75b..0716adecef 100755 --- a/qpid/python/examples/direct/listener.py +++ b/qpid/python/examples/direct/listener.py @@ -48,10 +48,6 @@ password="guest" # 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 : diff --git a/qpid/python/examples/fanout/fanout_consumer.py b/qpid/python/examples/fanout/fanout_consumer.py index 15452390a0..4a0e8ef488 100755 --- a/qpid/python/examples/fanout/fanout_consumer.py +++ b/qpid/python/examples/fanout/fanout_consumer.py @@ -25,10 +25,6 @@ password="guest" # 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 : diff --git a/qpid/python/examples/fanout/fanout_producer.py b/qpid/python/examples/fanout/fanout_producer.py index f5b589c861..3950ca6d2e 100755 --- a/qpid/python/examples/fanout/fanout_producer.py +++ b/qpid/python/examples/fanout/fanout_producer.py @@ -24,10 +24,6 @@ password="guest" # 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 : diff --git a/qpid/python/examples/fanout/listener.py b/qpid/python/examples/fanout/listener.py index 56acd50e10..b2ed85045b 100755 --- a/qpid/python/examples/fanout/listener.py +++ b/qpid/python/examples/fanout/listener.py @@ -45,10 +45,6 @@ password="guest" # 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 : diff --git a/qpid/python/examples/pubsub/topic_publisher.py b/qpid/python/examples/pubsub/topic_publisher.py index fb817c15f4..8cf1b08644 100755 --- a/qpid/python/examples/pubsub/topic_publisher.py +++ b/qpid/python/examples/pubsub/topic_publisher.py @@ -33,10 +33,6 @@ password="guest" # 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 : diff --git a/qpid/python/examples/pubsub/topic_subscriber.py b/qpid/python/examples/pubsub/topic_subscriber.py index a4210c83ef..4ba8e6a680 100755 --- a/qpid/python/examples/pubsub/topic_subscriber.py +++ b/qpid/python/examples/pubsub/topic_subscriber.py @@ -57,10 +57,6 @@ password="guest" # 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 : diff --git a/qpid/python/examples/request-response/client.py b/qpid/python/examples/request-response/client.py index 7bb4ee3462..8d40aca5bb 100755 --- a/qpid/python/examples/request-response/client.py +++ b/qpid/python/examples/request-response/client.py @@ -48,10 +48,6 @@ password="guest" # 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 : diff --git a/qpid/python/examples/request-response/server.py b/qpid/python/examples/request-response/server.py index dbe4b88208..99b1431509 100755 --- a/qpid/python/examples/request-response/server.py +++ b/qpid/python/examples/request-response/server.py @@ -40,10 +40,6 @@ password="guest" # 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 : diff --git a/qpid/python/examples/xml-exchange/declare_queues.py b/qpid/python/examples/xml-exchange/declare_queues.py index 8985c20cab..bd17da5013 100755 --- a/qpid/python/examples/xml-exchange/declare_queues.py +++ b/qpid/python/examples/xml-exchange/declare_queues.py @@ -28,10 +28,6 @@ password="guest" # 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 : diff --git a/qpid/python/examples/xml-exchange/listener.py b/qpid/python/examples/xml-exchange/listener.py index f2f9105091..db12d57e3e 100755 --- a/qpid/python/examples/xml-exchange/listener.py +++ b/qpid/python/examples/xml-exchange/listener.py @@ -45,10 +45,6 @@ password="guest" # 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 : diff --git a/qpid/python/examples/xml-exchange/xml_consumer.py b/qpid/python/examples/xml-exchange/xml_consumer.py index 047faec668..22973b2bd9 100755 --- a/qpid/python/examples/xml-exchange/xml_consumer.py +++ b/qpid/python/examples/xml-exchange/xml_consumer.py @@ -27,10 +27,6 @@ password="guest" # 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 : diff --git a/qpid/python/examples/xml-exchange/xml_producer.py b/qpid/python/examples/xml-exchange/xml_producer.py index 435045b0fa..72c5bdb53a 100755 --- a/qpid/python/examples/xml-exchange/xml_producer.py +++ b/qpid/python/examples/xml-exchange/xml_producer.py @@ -45,10 +45,6 @@ password="guest" # 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 : -- cgit v1.2.1 From 2becbf6ae901b1c7aecebe95087fd308fc611627 Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Wed, 11 Jun 2008 21:31:12 +0000 Subject: replaced example usages of message_flow with the start() method git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@666850 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/direct/direct_consumer.py | 5 ++--- qpid/python/examples/direct/listener.py | 3 +-- qpid/python/examples/fanout/fanout_consumer.py | 5 ++--- qpid/python/examples/fanout/listener.py | 5 ++--- qpid/python/examples/pubsub/topic_subscriber.py | 3 +-- qpid/python/examples/request-response/client.py | 3 +-- qpid/python/examples/request-response/server.py | 6 ++---- qpid/python/examples/xml-exchange/listener.py | 5 ++--- qpid/python/examples/xml-exchange/xml_consumer.py | 5 ++--- 9 files changed, 15 insertions(+), 25 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/direct/direct_consumer.py b/qpid/python/examples/direct/direct_consumer.py index e421a417c1..23577e9f53 100755 --- a/qpid/python/examples/direct/direct_consumer.py +++ b/qpid/python/examples/direct/direct_consumer.py @@ -51,11 +51,10 @@ queue = session.incoming(local_queue_name) # Call message_subscribe() to tell the broker to deliver messages # from the AMQP queue to this local client queue. The broker will # start delivering messages as soon as credit is allocated using -# session.message_flow(). +# queue.start(). session.message_subscribe(queue="message_queue", destination=local_queue_name) -session.message_flow(local_queue_name, session.credit_unit.message, 0xFFFFFFFF) -session.message_flow(local_queue_name, session.credit_unit.byte, 0xFFFFFFFF) +queue.start() # Initialize 'final' and 'content', variables used to identify the last message. diff --git a/qpid/python/examples/direct/listener.py b/qpid/python/examples/direct/listener.py index 0716adecef..66927eca4b 100755 --- a/qpid/python/examples/direct/listener.py +++ b/qpid/python/examples/direct/listener.py @@ -74,8 +74,7 @@ queue = session.incoming(local_queue_name) # start delivering messages as soon as message_subscribe() is called. session.message_subscribe(queue="message_queue", destination=local_queue_name) -session.message_flow(local_queue_name, session.credit_unit.message, 0xFFFFFFFF) -session.message_flow(local_queue_name, session.credit_unit.byte, 0xFFFFFFFF) +queue.start() receiver = Receiver() queue.listen (receiver.Handler) diff --git a/qpid/python/examples/fanout/fanout_consumer.py b/qpid/python/examples/fanout/fanout_consumer.py index 4a0e8ef488..a2b1b30141 100755 --- a/qpid/python/examples/fanout/fanout_consumer.py +++ b/qpid/python/examples/fanout/fanout_consumer.py @@ -51,12 +51,11 @@ session.exchange_bind(queue=server_queue_name, exchange="amq.fanout") local_queue_name = "local_queue" local_queue = session.incoming(local_queue_name) -# Call message_consume() to tell the server to deliver messages +# Call message_subscribe() to tell the server to deliver messages # from the AMQP queue to this local client queue. session.message_subscribe(queue=server_queue_name, destination=local_queue_name) -session.message_flow(local_queue_name, session.credit_unit.message, 0xFFFFFFFF) -session.message_flow(local_queue_name, session.credit_unit.byte, 0xFFFFFFFF) +local_queue.start() print "Subscribed to queue " + server_queue_name sys.stdout.flush() diff --git a/qpid/python/examples/fanout/listener.py b/qpid/python/examples/fanout/listener.py index b2ed85045b..74ae858127 100755 --- a/qpid/python/examples/fanout/listener.py +++ b/qpid/python/examples/fanout/listener.py @@ -79,11 +79,10 @@ local_queue = session.incoming(local_queue_name) # Call message_subscribe() to tell the broker to deliver messages # from the AMQP queue to this local client queue. The broker will -# start delivering messages as soon as message_subscribe() is called. +# start delivering messages as soon as local_queue.start() is called. session.message_subscribe(queue=server_queue_name, destination=local_queue_name) -session.message_flow(local_queue_name, session.credit_unit.message, 0xFFFFFFFF) -session.message_flow(local_queue_name, session.credit_unit.byte, 0xFFFFFFFF) +local_queue.start() receiver = Receiver () local_queue.listen (receiver.Handler) diff --git a/qpid/python/examples/pubsub/topic_subscriber.py b/qpid/python/examples/pubsub/topic_subscriber.py index 4ba8e6a680..039cc0c55b 100755 --- a/qpid/python/examples/pubsub/topic_subscriber.py +++ b/qpid/python/examples/pubsub/topic_subscriber.py @@ -41,8 +41,7 @@ def subscribe_queue(server_queue_name, local_queue_name): queue = session.incoming(local_queue_name) session.message_subscribe(queue=server_queue_name, destination=local_queue_name) - session.message_flow(local_queue_name, session.credit_unit.message, 0xFFFFFFFF) - session.message_flow(local_queue_name, session.credit_unit.byte, 0xFFFFFFFF) + queue.start() return queue diff --git a/qpid/python/examples/request-response/client.py b/qpid/python/examples/request-response/client.py index 8d40aca5bb..a9ecd5c78f 100755 --- a/qpid/python/examples/request-response/client.py +++ b/qpid/python/examples/request-response/client.py @@ -81,8 +81,7 @@ queue = session.incoming(local_queue_name) # available. session.message_subscribe(queue=reply_to, destination=local_queue_name) -session.message_flow(local_queue_name, session.credit_unit.message, 0xFFFFFFFF) -session.message_flow(local_queue_name, session.credit_unit.byte, 0xFFFFFFFF) +queue.start() # Send some messages to the server's request queue diff --git a/qpid/python/examples/request-response/server.py b/qpid/python/examples/request-response/server.py index 99b1431509..05ee051c57 100755 --- a/qpid/python/examples/request-response/server.py +++ b/qpid/python/examples/request-response/server.py @@ -60,9 +60,9 @@ session.exchange_bind(exchange="amq.direct", queue="request", binding_key="reque local_queue_name = "local_queue" session.message_subscribe(queue="request", destination=local_queue_name) -session.message_flow(local_queue_name, session.credit_unit.message, 0xFFFFFFFF) -session.message_flow(local_queue_name, session.credit_unit.byte, 0xFFFFFFFF) +queue = session.incoming(local_queue_name) +queue.start() # Remind the user to start the client program @@ -72,8 +72,6 @@ sys.stdout.flush() # Respond to each request -queue = session.incoming(local_queue_name) - # If we get a message, send it back to the user (as indicated in the # ReplyTo property) diff --git a/qpid/python/examples/xml-exchange/listener.py b/qpid/python/examples/xml-exchange/listener.py index db12d57e3e..dec824dddf 100755 --- a/qpid/python/examples/xml-exchange/listener.py +++ b/qpid/python/examples/xml-exchange/listener.py @@ -68,11 +68,10 @@ local_queue = session.incoming(local_queue_name) # Call message_subscribe() to tell the broker to deliver messages # from the AMQP queue to this local client queue. The broker will -# start delivering messages as soon as message_subscribe() is called. +# start delivering messages as soon as local_queue.start() is called. session.message_subscribe(queue="message_queue", destination=local_queue_name) -session.message_flow(local_queue_name, session.credit_unit.message, 0xFFFFFFFF) -session.message_flow(local_queue_name, session.credit_unit.byte, 0xFFFFFFFF) +local_queue.start() receiver = Receiver () local_queue.listen (receiver.Handler) diff --git a/qpid/python/examples/xml-exchange/xml_consumer.py b/qpid/python/examples/xml-exchange/xml_consumer.py index 22973b2bd9..0ab079e7a6 100755 --- a/qpid/python/examples/xml-exchange/xml_consumer.py +++ b/qpid/python/examples/xml-exchange/xml_consumer.py @@ -51,11 +51,10 @@ local_queue = session.incoming(local_queue_name) # Call message_consume() to tell the broker to deliver messages # from the AMQP queue to this local client queue. The broker will -# start delivering messages as soon as message_consume() is called. +# start delivering messages as soon as local_queue.start() is called. session.message_subscribe(queue="message_queue", destination=local_queue_name) -session.message_flow(local_queue_name, session.credit_unit.message, 0xFFFFFFFF) -session.message_flow(local_queue_name, session.credit_unit.byte, 0xFFFFFFFF) +local_queue.start() # Initialize 'final' and 'content', variables used to identify the last message. -- cgit v1.2.1 From 720bc5b1e76bc150e30a41789ae5ca529a03725e Mon Sep 17 00:00:00 2001 From: Aidan Skinner Date: Thu, 28 Aug 2008 19:26:51 +0000 Subject: Add ASL to everywhere, to everything. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@689937 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/direct/declare_queues.py | 18 ++++++++++++++++++ qpid/python/examples/direct/direct_consumer.py | 18 ++++++++++++++++++ qpid/python/examples/direct/direct_producer.py | 18 ++++++++++++++++++ qpid/python/examples/direct/listener.py | 18 ++++++++++++++++++ qpid/python/examples/fanout/fanout_consumer.py | 18 ++++++++++++++++++ qpid/python/examples/fanout/fanout_producer.py | 18 ++++++++++++++++++ qpid/python/examples/fanout/listener.py | 18 ++++++++++++++++++ qpid/python/examples/pubsub/topic_publisher.py | 18 ++++++++++++++++++ qpid/python/examples/pubsub/topic_subscriber.py | 18 ++++++++++++++++++ qpid/python/examples/request-response/client.py | 18 ++++++++++++++++++ qpid/python/examples/request-response/server.py | 18 ++++++++++++++++++ qpid/python/examples/xml-exchange/declare_queues.py | 18 ++++++++++++++++++ qpid/python/examples/xml-exchange/listener.py | 18 ++++++++++++++++++ qpid/python/examples/xml-exchange/xml_consumer.py | 18 ++++++++++++++++++ qpid/python/examples/xml-exchange/xml_producer.py | 18 ++++++++++++++++++ 15 files changed, 270 insertions(+) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/direct/declare_queues.py b/qpid/python/examples/direct/declare_queues.py index f0c34fa8c9..3cc4a10c0b 100755 --- a/qpid/python/examples/direct/declare_queues.py +++ b/qpid/python/examples/direct/declare_queues.py @@ -1,4 +1,22 @@ #!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# """ declare_queues.py diff --git a/qpid/python/examples/direct/direct_consumer.py b/qpid/python/examples/direct/direct_consumer.py index 23577e9f53..6e30541d6c 100755 --- a/qpid/python/examples/direct/direct_consumer.py +++ b/qpid/python/examples/direct/direct_consumer.py @@ -1,4 +1,22 @@ #!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# """ direct_consumer.py diff --git a/qpid/python/examples/direct/direct_producer.py b/qpid/python/examples/direct/direct_producer.py index 870ce66e78..984d112243 100755 --- a/qpid/python/examples/direct/direct_producer.py +++ b/qpid/python/examples/direct/direct_producer.py @@ -1,4 +1,22 @@ #!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# """ direct_producer.py diff --git a/qpid/python/examples/direct/listener.py b/qpid/python/examples/direct/listener.py index 66927eca4b..d1c4b1d645 100755 --- a/qpid/python/examples/direct/listener.py +++ b/qpid/python/examples/direct/listener.py @@ -1,4 +1,22 @@ #!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# """ listener.py diff --git a/qpid/python/examples/fanout/fanout_consumer.py b/qpid/python/examples/fanout/fanout_consumer.py index a2b1b30141..d2a6f5242f 100755 --- a/qpid/python/examples/fanout/fanout_consumer.py +++ b/qpid/python/examples/fanout/fanout_consumer.py @@ -1,4 +1,22 @@ #!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# """ fanout_consumer.py diff --git a/qpid/python/examples/fanout/fanout_producer.py b/qpid/python/examples/fanout/fanout_producer.py index 3950ca6d2e..4d24a460d1 100755 --- a/qpid/python/examples/fanout/fanout_producer.py +++ b/qpid/python/examples/fanout/fanout_producer.py @@ -1,4 +1,22 @@ #!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# """ fanout_producer.py diff --git a/qpid/python/examples/fanout/listener.py b/qpid/python/examples/fanout/listener.py index 74ae858127..9863357a41 100755 --- a/qpid/python/examples/fanout/listener.py +++ b/qpid/python/examples/fanout/listener.py @@ -1,4 +1,22 @@ #!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# """ listener.py diff --git a/qpid/python/examples/pubsub/topic_publisher.py b/qpid/python/examples/pubsub/topic_publisher.py index 8cf1b08644..b50d5fa8ca 100755 --- a/qpid/python/examples/pubsub/topic_publisher.py +++ b/qpid/python/examples/pubsub/topic_publisher.py @@ -1,4 +1,22 @@ #!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# """ topic_publisher.py diff --git a/qpid/python/examples/pubsub/topic_subscriber.py b/qpid/python/examples/pubsub/topic_subscriber.py index 039cc0c55b..7a886974ee 100755 --- a/qpid/python/examples/pubsub/topic_subscriber.py +++ b/qpid/python/examples/pubsub/topic_subscriber.py @@ -1,4 +1,22 @@ #!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# """ topic_subscriber.py diff --git a/qpid/python/examples/request-response/client.py b/qpid/python/examples/request-response/client.py index a9ecd5c78f..563e4f2992 100755 --- a/qpid/python/examples/request-response/client.py +++ b/qpid/python/examples/request-response/client.py @@ -1,4 +1,22 @@ #!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# """ client.py diff --git a/qpid/python/examples/request-response/server.py b/qpid/python/examples/request-response/server.py index 05ee051c57..7300ced03a 100755 --- a/qpid/python/examples/request-response/server.py +++ b/qpid/python/examples/request-response/server.py @@ -1,4 +1,22 @@ #!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# """ server.py diff --git a/qpid/python/examples/xml-exchange/declare_queues.py b/qpid/python/examples/xml-exchange/declare_queues.py index bd17da5013..d8c2d0c34f 100755 --- a/qpid/python/examples/xml-exchange/declare_queues.py +++ b/qpid/python/examples/xml-exchange/declare_queues.py @@ -1,4 +1,22 @@ #!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# """ declare_queues.py diff --git a/qpid/python/examples/xml-exchange/listener.py b/qpid/python/examples/xml-exchange/listener.py index dec824dddf..c6fa4ec57d 100755 --- a/qpid/python/examples/xml-exchange/listener.py +++ b/qpid/python/examples/xml-exchange/listener.py @@ -1,4 +1,22 @@ #!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# """ listener.py diff --git a/qpid/python/examples/xml-exchange/xml_consumer.py b/qpid/python/examples/xml-exchange/xml_consumer.py index 0ab079e7a6..e414d98991 100755 --- a/qpid/python/examples/xml-exchange/xml_consumer.py +++ b/qpid/python/examples/xml-exchange/xml_consumer.py @@ -1,4 +1,22 @@ #!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# """ direct_consumer.py diff --git a/qpid/python/examples/xml-exchange/xml_producer.py b/qpid/python/examples/xml-exchange/xml_producer.py index 72c5bdb53a..2641b185c6 100755 --- a/qpid/python/examples/xml-exchange/xml_producer.py +++ b/qpid/python/examples/xml-exchange/xml_producer.py @@ -1,4 +1,22 @@ #!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# """ xml_producer.py -- cgit v1.2.1 From fa2afe4e0015cb48856525b1385ecaee638d045d Mon Sep 17 00:00:00 2001 From: Rajith Muditha Attapattu Date: Mon, 15 Dec 2008 18:12:25 +0000 Subject: Added license headers to the following files. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@726752 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/direct/verify | 19 +++++++++++++++++++ qpid/python/examples/fanout/verify | 19 +++++++++++++++++++ qpid/python/examples/pubsub/verify | 19 +++++++++++++++++++ qpid/python/examples/request-response/verify | 19 +++++++++++++++++++ qpid/python/examples/xml-exchange/verify | 19 +++++++++++++++++++ 5 files changed, 95 insertions(+) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/direct/verify b/qpid/python/examples/direct/verify index 01d81a18a1..92f87bf827 100644 --- a/qpid/python/examples/direct/verify +++ b/qpid/python/examples/direct/verify @@ -1,3 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + # See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify clients ./declare_queues.py ./direct_producer.py ./direct_consumer.py outputs ./declare_queues.py.out ./direct_producer.py.out ./direct_consumer.py.out diff --git a/qpid/python/examples/fanout/verify b/qpid/python/examples/fanout/verify index 6a3132a94f..9e5c364bfa 100644 --- a/qpid/python/examples/fanout/verify +++ b/qpid/python/examples/fanout/verify @@ -1,3 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + # See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify background "Subscribed" ./fanout_consumer.py background "Subscribed" ./fanout_consumer.py diff --git a/qpid/python/examples/pubsub/verify b/qpid/python/examples/pubsub/verify index 963d2e32e1..cf1bade62e 100644 --- a/qpid/python/examples/pubsub/verify +++ b/qpid/python/examples/pubsub/verify @@ -1,3 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + # See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify background "Queues created" ./topic_subscriber.py clients ./topic_publisher.py diff --git a/qpid/python/examples/request-response/verify b/qpid/python/examples/request-response/verify index cf8151d4e4..3c058febb2 100644 --- a/qpid/python/examples/request-response/verify +++ b/qpid/python/examples/request-response/verify @@ -1,3 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + # See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify background "Request server running" ./server.py clients ./client.py diff --git a/qpid/python/examples/xml-exchange/verify b/qpid/python/examples/xml-exchange/verify index bf05463f1d..a93a32dc90 100644 --- a/qpid/python/examples/xml-exchange/verify +++ b/qpid/python/examples/xml-exchange/verify @@ -1,3 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + # See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify clients ./declare_queues.py ./xml_producer.py ./xml_consumer.py outputs ./declare_queues.py.out ./xml_producer.py.out ./xml_consumer.py.out -- cgit v1.2.1 From cab5db31674b25b3c70b2ac5ed4ea97ab413f932 Mon Sep 17 00:00:00 2001 From: Jonathan Robie Date: Tue, 16 Dec 2008 18:50:55 +0000 Subject: Modified Connect() constructor throughout. User name and password are now supplied for the connection. (Someone changed this, and it no longer matched the original tutorial.) git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@727116 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/direct/declare_queues.py | 2 +- qpid/python/examples/direct/direct_consumer.py | 2 +- qpid/python/examples/direct/direct_producer.py | 2 +- qpid/python/examples/direct/listener.py | 2 +- qpid/python/examples/fanout/fanout_consumer.py | 2 +- qpid/python/examples/fanout/fanout_producer.py | 2 +- qpid/python/examples/fanout/listener.py | 2 +- qpid/python/examples/pubsub/topic_subscriber.py | 2 +- qpid/python/examples/request-response/client.py | 2 +- qpid/python/examples/request-response/server.py | 2 +- qpid/python/examples/xml-exchange/declare_queues.py | 2 +- qpid/python/examples/xml-exchange/listener.py | 2 +- qpid/python/examples/xml-exchange/xml_consumer.py | 2 +- qpid/python/examples/xml-exchange/xml_producer.py | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/direct/declare_queues.py b/qpid/python/examples/direct/declare_queues.py index 3cc4a10c0b..13818ee9d7 100755 --- a/qpid/python/examples/direct/declare_queues.py +++ b/qpid/python/examples/direct/declare_queues.py @@ -54,7 +54,7 @@ if len(sys.argv) > 2 : # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket) +connection = Connection (sock=socket, username=user, password=password) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/direct/direct_consumer.py b/qpid/python/examples/direct/direct_consumer.py index 6e30541d6c..b07e53c5c7 100755 --- a/qpid/python/examples/direct/direct_consumer.py +++ b/qpid/python/examples/direct/direct_consumer.py @@ -52,7 +52,7 @@ if len(sys.argv) > 2 : # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket) +connection = Connection (sock=socket, username=user, password=password) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/direct/direct_producer.py b/qpid/python/examples/direct/direct_producer.py index 984d112243..fcbb4675e4 100755 --- a/qpid/python/examples/direct/direct_producer.py +++ b/qpid/python/examples/direct/direct_producer.py @@ -52,7 +52,7 @@ if len(sys.argv) > 2 : # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket) +connection = Connection (sock=socket, username=user, password=password) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/direct/listener.py b/qpid/python/examples/direct/listener.py index d1c4b1d645..9d06bd3929 100755 --- a/qpid/python/examples/direct/listener.py +++ b/qpid/python/examples/direct/listener.py @@ -73,7 +73,7 @@ if len(sys.argv) > 2 : # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket) +connection = Connection (sock=socket, username=user, password=password) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/fanout/fanout_consumer.py b/qpid/python/examples/fanout/fanout_consumer.py index d2a6f5242f..0452baa8da 100755 --- a/qpid/python/examples/fanout/fanout_consumer.py +++ b/qpid/python/examples/fanout/fanout_consumer.py @@ -50,7 +50,7 @@ if len(sys.argv) > 2 : # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket) +connection = Connection (sock=socket, username=user, password=password) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/fanout/fanout_producer.py b/qpid/python/examples/fanout/fanout_producer.py index 4d24a460d1..c4df252c70 100755 --- a/qpid/python/examples/fanout/fanout_producer.py +++ b/qpid/python/examples/fanout/fanout_producer.py @@ -49,7 +49,7 @@ if len(sys.argv) > 2 : # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket) +connection = Connection (sock=socket, username=user, password=password) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/fanout/listener.py b/qpid/python/examples/fanout/listener.py index 9863357a41..29db402e9d 100755 --- a/qpid/python/examples/fanout/listener.py +++ b/qpid/python/examples/fanout/listener.py @@ -70,7 +70,7 @@ if len(sys.argv) > 2 : # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket) +connection = Connection (sock=socket, username=user, password=password) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/pubsub/topic_subscriber.py b/qpid/python/examples/pubsub/topic_subscriber.py index 7a886974ee..489c7cbb19 100755 --- a/qpid/python/examples/pubsub/topic_subscriber.py +++ b/qpid/python/examples/pubsub/topic_subscriber.py @@ -81,7 +81,7 @@ if len(sys.argv) > 2 : # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket) +connection = Connection (sock=socket, username=user, password=password) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/request-response/client.py b/qpid/python/examples/request-response/client.py index 563e4f2992..b29fcf3ea7 100755 --- a/qpid/python/examples/request-response/client.py +++ b/qpid/python/examples/request-response/client.py @@ -73,7 +73,7 @@ if len(sys.argv) > 2 : # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket) +connection = Connection (sock=socket, username=user, password=password) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/request-response/server.py b/qpid/python/examples/request-response/server.py index 7300ced03a..a80c4541e4 100755 --- a/qpid/python/examples/request-response/server.py +++ b/qpid/python/examples/request-response/server.py @@ -64,7 +64,7 @@ if len(sys.argv) > 2 : port=int(sys.argv[2]) socket = connect(host, port) -connection = Connection (sock=socket) +connection = Connection (sock=socket, username=user, password=password) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/xml-exchange/declare_queues.py b/qpid/python/examples/xml-exchange/declare_queues.py index d8c2d0c34f..ca40af5dc5 100755 --- a/qpid/python/examples/xml-exchange/declare_queues.py +++ b/qpid/python/examples/xml-exchange/declare_queues.py @@ -53,7 +53,7 @@ if len(sys.argv) > 2 : # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket) +connection = Connection (sock=socket, username=user, password=password) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/xml-exchange/listener.py b/qpid/python/examples/xml-exchange/listener.py index c6fa4ec57d..a56f5d6018 100755 --- a/qpid/python/examples/xml-exchange/listener.py +++ b/qpid/python/examples/xml-exchange/listener.py @@ -70,7 +70,7 @@ if len(sys.argv) > 2 : # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket) +connection = Connection (sock=socket, username=user, password=password) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/xml-exchange/xml_consumer.py b/qpid/python/examples/xml-exchange/xml_consumer.py index e414d98991..cd89110b05 100755 --- a/qpid/python/examples/xml-exchange/xml_consumer.py +++ b/qpid/python/examples/xml-exchange/xml_consumer.py @@ -52,7 +52,7 @@ if len(sys.argv) > 2 : # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket) +connection = Connection (sock=socket, username=user, password=password) connection.start() session = connection.session(str(uuid4())) diff --git a/qpid/python/examples/xml-exchange/xml_producer.py b/qpid/python/examples/xml-exchange/xml_producer.py index 2641b185c6..fa97cab4e1 100755 --- a/qpid/python/examples/xml-exchange/xml_producer.py +++ b/qpid/python/examples/xml-exchange/xml_producer.py @@ -70,7 +70,7 @@ if len(sys.argv) > 2 : # Create a connection. socket = connect(host, port) -connection = Connection (sock=socket) +connection = Connection (sock=socket, username=user, password=password) connection.start() session = connection.session(str(uuid4())) -- cgit v1.2.1 From 6b4f3c57a9cbaa808e66cd284af90a70da7172e1 Mon Sep 17 00:00:00 2001 From: Jonathan Robie Date: Thu, 12 Feb 2009 16:08:27 +0000 Subject: Instructions on how to run the Python examples. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@743788 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/README | 267 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 267 insertions(+) create mode 100644 qpid/python/examples/README (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/README b/qpid/python/examples/README new file mode 100644 index 0000000000..24d449afc2 --- /dev/null +++ b/qpid/python/examples/README @@ -0,0 +1,267 @@ +Running the Python Examples +============================ + + +Running the Direct Examples +---------------------------- + +To run the direct examples, do the following: + +1. Make sure that a qpidd broker is running: + + $ ps -eaf | grep qpidd + + If a broker is running, you should see the qpidd process in the output of the above command. + +2.Declare a message queue and bind it to an exchange by running declare_queues.py, as follows: + + $ python declare_queues.py + + This program has no output. After this program has been run, all messages sent to the amq.direct exchange using the routing key routing_key are sent to the queue named message_queue. + +3.Publish a series of messages to the amq.direct exchange by running direct_producer.py, as follows: + + $ python direct_producer.py + +This program has no output; the messages are routed to the message queue, as instructed by the binding. + +4. Read the messages from the message queue using direct_consumer.py or listener.py, as follows: + + $ python direct_consumer.py + + or + + $ python listener.py + +You should see the following output: + +message 0 +message 1 +message 2 +message 3 +message 4 +message 5 +message 6 +message 7 +message 8 +message 9 +That's all, folks! + + + +Running the Fanout Examples +---------------------------- + +To run the programs for the Fanout example, do the following: + +1. Make sure that a qpidd broker is running: + + $ ps -eaf | grep qpidd + +If a broker is running, you should see the qpidd process in the output of the above command. + +2. In separate windows, start two or more fanout consumers or fanout listeners as follows: + + $ python fanout_consumer.py + + or + + $ python listener.py + +These programs each create a private queue, bind it to the amq.fanout exchange, and wait for messages to arrive on their queue. + +3. In a separate window, publish a series of messages to the amq.fanout exchange by running fanout_producer.py, as follows: + + $ python fanout_producer.py + +This program has no output; the messages are routed to the message queue, as instructed by the binding. + +4. Go to the windows where you are running consumers or listeners. You should see the following output for each listener or consumer: + + message 0 + message 1 + message 2 + message 3 + message 4 + message 5 + message 6 + message 7 + message 8 + message 9 + That's all, folks! + + + +Running the Publish-Subscribe Examples +--------------------------------------- + +To run the programs for the Publish-Subscribe example, do the following: + +1. Make sure that a qpidd broker is running: + + $ ps -eaf | grep qpidd + +If a broker is running, you should see the qpidd process in the output of the above command. + +2. In separate windows, start one or more topic subscribers by running topic_subscriber.py, as follows: + + $ python topic_subscriber.py + +You will see output similar to this: + + Queues created - please start the topic producer + Subscribing local queue 'local_news' to news-53408183-fcee-4b92-950b-90abb297e739' + Subscribing local queue 'local_weather' to weather-53408183-fcee-4b92-950b-90abb297e739' + Subscribing local queue 'local_usa' to usa-53408183-fcee-4b92-950b-90abb297e739' + Subscribing local queue 'local_europe' to europe-53408183-fcee-4b92-950b-90abb297e739' + Messages on 'news' queue: + +Each topic consumer creates a set of private queues, and binds each queue to the amq.topic exchange together with a binding that indicates which messages should be routed to the queue. + +3.In another window, start the topic publisher, which publishes messages to the amq.topic exchange, as follows: + + $ python topic_publisher.py + +This program has no output; the messages are routed to the message queues for each topic_consumer as specified by the bindings the consumer created. + +4. Go back to the window for each topic consumer. You should see output like this: + + Messages on 'news' queue: + usa.news 0 + usa.news 1 + usa.news 2 + usa.news 3 + usa.news 4 + europe.news 0 + europe.news 1 + europe.news 2 + europe.news 3 + europe.news 4 + That's all, folks! + Messages on 'weather' queue: + usa.weather 0 + usa.weather 1 + usa.weather 2 + usa.weather 3 + usa.weather 4 + europe.weather 0 + europe.weather 1 + europe.weather 2 + europe.weather 3 + europe.weather 4 + That's all, folks! + Messages on 'usa' queue: + usa.news 0 + usa.news 1 + usa.news 2 + usa.news 3 + usa.news 4 + usa.weather 0 + usa.weather 1 + usa.weather 2 + usa.weather 3 + usa.weather 4 + That's all, folks! + Messages on 'europe' queue: + europe.news 0 + europe.news 1 + europe.news 2 + europe.news 3 + europe.news 4 + europe.weather 0 + europe.weather 1 + europe.weather 2 + europe.weather 3 + europe.weather 4 + That's all, folks! + + +Running the Request/Response Examples +-------------------------------------- + +To run the programs for the Request/Response example, do the following: + +1. Make sure that a qpidd broker is running: + + $ ps -eaf | grep qpidd + +If a broker is running, you should see the qpidd process in the output of the above command. + +2. Run the server. + + $ python server.py + +You should see the following output: + + Request server running - run your client now. + (Times out after 100 seconds ...) + +3. In a separate window, start a client: + + $ python client.py + +You should see the following output: + + Request: Twas brillig, and the slithy toves + Request: Did gyre and gimble in the wabe. + Request: All mimsy were the borogroves, + Request: And the mome raths outgrabe. + Messages on queue: reply_to:db0f862e-6b36-4e0f-a4b2-ad049eb435ce + Response: TWAS BRILLIG, AND THE SLITHY TOVES + Response: DID GYRE AND GIMBLE IN THE WABE. + Response: ALL MIMSY WERE THE BOROGROVES, + Response: AND THE MOME RATHS OUTGRABE. + No more messages! + + +Running the XML-based Routing Examples +--------------------------------------- + +To run the programs for the XML-based Routing example, do the following: + +1. Make sure that a qpidd broker is running: + + $ ps -eaf | grep qpidd + +If a broker is running, you should see the qpidd process in the output of the above command. + +2. Declare an XML exchange and a message queue, then bind the queue to the exchange by running declare_queues.py, as follows: + + $ python declare_queues.py + +This program has no output. After this program has been run, all messages sent to the xml exchange using the routing key weather are sent to the queue named message_queue if they satisfy the conditions specified in the following XQuery, which is used in the binding: + + let $w := ./weather + return $w/station = 'Raleigh-Durham International Airport (KRDU)' + and $w/temperature_f > 50 + and $w/temperature_f - $w/dewpoint > 5 + and $w/wind_speed_mph > 7 + and $w/wind_speed_mph < 20 + +3. Publish a series of messages to the xml exchange by running xml_producer.py, as follows: + + $ python xml_producer.py + +The messages are routed to the message queue, as prescribed by the binding. Each message represents a weather report, such as this one: + + + Raleigh-Durham International Airport (KRDU) + 16 + 70 + 35 + + +4. Read the messages from the message queue using direct_consumer.py or listener.py, as follows: + + $ python xml_consumer.py + + or + + $ python listener.py + +You should see the following output: + +Raleigh-Durham International Airport (KRDU) +1670 +35 + -- cgit v1.2.1 From 6a644249ba25e38dfa6852dac3377e62aa7386df Mon Sep 17 00:00:00 2001 From: Jonathan Robie Date: Thu, 12 Mar 2009 18:59:07 +0000 Subject: Tests Unicode and handling of all datatypes in application headers. Things commented out don't work yet. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@752972 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/datatypes/client.py | 122 +++++++++++++++++++ qpid/python/examples/datatypes/server.py | 124 ++++++++++++++++++++ qpid/python/examples/datatypes/testdata.py | 180 +++++++++++++++++++++++++++++ qpid/python/examples/datatypes/verify | 24 ++++ 4 files changed, 450 insertions(+) create mode 100755 qpid/python/examples/datatypes/client.py create mode 100755 qpid/python/examples/datatypes/server.py create mode 100644 qpid/python/examples/datatypes/testdata.py create mode 100644 qpid/python/examples/datatypes/verify (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/datatypes/client.py b/qpid/python/examples/datatypes/client.py new file mode 100755 index 0000000000..088e529909 --- /dev/null +++ b/qpid/python/examples/datatypes/client.py @@ -0,0 +1,122 @@ +#!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +""" + client.py + + Client for testing use of Unicode and datatypes. + + Both client and server will be written in C++ and Python. + Tests can run clients and servers written in different + languages, and they can be run on 32-bit and 64-bit architectures. + +""" + +import qpid +import sys +import os +from qpid.util import connect +from qpid.connection import Connection +from qpid.datatypes import Message, RangedSet, uuid4 +from qpid.queue import Empty + +import testdata + +#----- Initialization -------------------------------------- + + +# Set parameters for login + +host="127.0.0.1" +port=5672 +user="guest" +password="guest" + +# If an alternate host or port has been specified, use that instead +# (this is used in our unit tests) +if len(sys.argv) > 1 : + host=sys.argv[1] +if len(sys.argv) > 2 : + port=int(sys.argv[2]) + +# Create a connection. +socket = connect(host, port) +connection = Connection (sock=socket, username=user, password=password) +connection.start() +session = connection.session(str(uuid4())) + + +#----- Main Body -- ---------------------------------------- + +# Create a response queue for the server to send responses to. Use the +# same string as the name of the queue and the name of the routing +# key. + +reply_to = "reply_to:" + session.name +session.queue_declare(queue=reply_to, exclusive=True) +session.exchange_bind(exchange="amq.direct", queue=reply_to, binding_key=reply_to) + +# Create a local queue and subscribe it to the response queue + +local_queue_name = "local_queue" +queue = session.incoming(local_queue_name) + +# Call message_subscribe() to tell the broker to deliver messages from +# the server's reply_to queue to our local client queue. The server +# will start delivering messages as soon as message credit is +# available. + +session.message_subscribe(queue=reply_to, destination=local_queue_name) +queue.start() + +# Set up the properties. Perhaps a few application headers? + +delivery_properties = session.delivery_properties(routing_key="request") + +message_properties = session.message_properties() + +message_properties.content_encoding="text/plain; charset='utf-8'" + +testdata.set_application_headers(message_properties) +message_properties.reply_to = session.reply_to("amq.direct", reply_to) + +# deliver the message - remember to encode the Unicode string! +request = Message(message_properties, delivery_properties, testdata.String_Greek.encode("utf8")) +session.message_transfer(destination="amq.direct", message=request) + +# Now see what messages the server sent to our reply_to queue + +try: + response = queue.get(timeout=10) + content = response.body + session.message_accept(RangedSet(response.id)) + testdata.check_message(response) + print "Response: " + content +except Empty: + print "No more messages!" + exit(1) +except: + print "Unexpected exception!" + exit(1) + +#----- Cleanup ------------------------------------------------ + +# Clean up before exiting so there are no open threads. + +session.close(timeout=10) diff --git a/qpid/python/examples/datatypes/server.py b/qpid/python/examples/datatypes/server.py new file mode 100755 index 0000000000..18e6fa4ad7 --- /dev/null +++ b/qpid/python/examples/datatypes/server.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +""" + server.py + + Server for testing use of Unicode and datatypes. + + Both client and server will be written in C++ and Python. + Tests can run clients and servers written in different + languages, and they can be run on 32-bit and 64-bit architectures. +""" + +import testdata + +import qpid +import sys +import os +from qpid.util import connect +from qpid.connection import Connection +from qpid.datatypes import Message, RangedSet, uuid4 +from qpid.queue import Empty + +#----- Functions ------------------------------------------- +def respond(session, request): + + # The routing key for the response is the request's reply-to + # property. The body for the response is the request's body, + # converted to upper case. + + testdata.check_message(request) + + message_properties = request.get("message_properties") + reply_to = message_properties.reply_to + + testdata.set_application_headers(message_properties) + + if reply_to == None: + raise Exception("This message is missing the 'reply_to' property, which is required") + + delivery_properties = session.delivery_properties(routing_key=reply_to["routing_key"]) + response = Message(delivery_properties, message_properties, testdata.String_Greek.encode("utf8")) + print "Sending response ..." + session.message_transfer(destination=reply_to["exchange"], message=response) + +#----- Initialization -------------------------------------- + + +# Set parameters for login + +host="127.0.0.1" +port=5672 +user="guest" +password="guest" + +# If an alternate host or port has been specified, use that instead +# (this is used in our unit tests) +if len(sys.argv) > 1 : + host=sys.argv[1] +if len(sys.argv) > 2 : + port=int(sys.argv[2]) + +socket = connect(host, port) +connection = Connection (sock=socket, username=user, password=password) +connection.start() +session = connection.session(str(uuid4())) + +#----- Main Body -- ---------------------------------------- + +# Create a request queue and subscribe to it + +session.queue_declare(queue="request", exclusive=True) +session.exchange_bind(exchange="amq.direct", queue="request", binding_key="request") + +local_queue_name = "local_queue" + +session.message_subscribe(queue="request", destination=local_queue_name) + +queue = session.incoming(local_queue_name) +queue.start() + +# Remind the user to start the client program + +print "Request server running - run your client now." +print "(Times out after 100 seconds ...)" +sys.stdout.flush() + +# Respond to each request + +# If we get a message, send it back to the user (as indicated in the +# ReplyTo property) + +while True: + try: + request = queue.get(timeout=100) + session.message_accept(RangedSet(request.id)) + + respond(session, request) + except Empty: + print "No more messages!" + break; + + +#----- Cleanup ------------------------------------------------ + +# Clean up before exiting so there are no open threads. + +session.close(timeout=10) diff --git a/qpid/python/examples/datatypes/testdata.py b/qpid/python/examples/datatypes/testdata.py new file mode 100644 index 0000000000..cdf140d400 --- /dev/null +++ b/qpid/python/examples/datatypes/testdata.py @@ -0,0 +1,180 @@ +# -*- encoding: utf-8 -*- + +from qpid.datatypes import uuid4, timestamp + +#----- Some variables to test boundary conditions on various data types + +void = None +boolean_true = True +boolean_false = False +Uint8_0 = 0 +Uint8_max = 255 +Uint16_0 = 0 +Uint16_max = 65535 +Uint32_0 = 0 +Uint32_max = 4294967295 +Uint64_0 = 0 +Uint64_max = 18446744073709551615 +Int8_min = -128 +Int8_0 = 0 +Int8_max = 127 +Int16_min = -32768 +Int16_0 = 0 +Int16_max = 32767 +Int32_min = -2147483648 +Int32_0 = 0 +Int32_max = 2147483647 +Int64_min = -9223372036854775808 +Int64_0 = 0 +Int64_max = 9223372036854775807 + +Float_pi = 3.14159265 +Float_neg = -1E4 +Float_big = 1267.43233E12 +Float_small = 12.78e-12 +Float_neg0 = -0 +Float_pos0 = 0 +Float_INF = float('inf') +Float_Negative_INF = float('-inf') + +Double_pi = 3.1415926535897932384626433832795 +Double_neg = -1E4 +Double_big = 1267.43233E12 +Double_small = 12.78e-2 +Double_neg0 = -0 +Double_pos0 = 0 +Double_INF = float('inf') +Double_Negative_INF = float('-inf') + +char_1byte = u'0024' # $ +char_2byte = u'00A2' # ¢ +char_3byte = u'20AC' # € +char_4byte = u'10ABCD' + +timestamp = timestamp() + +UUID = uuid4() + +String_Greek = u"ἐξίσταντο δὲ πάντες καὶ διηπόρουν, ἄλλος πρὸς ἄλλον λέγοντες, Τί θέλει τοῦτο εἶναι;" + +String_Empty = "" + +#----- A few functions ---------------------------------------------------------- + +def near_enough(float1, float2, delta): + return abs(float1-float2) < delta + +def set_application_headers(message_properties): + + message_properties.application_headers = {} + message_properties.application_headers["void"] = None + message_properties.application_headers["boolean_true"] = boolean_true + message_properties.application_headers["boolean_false"] = boolean_false + message_properties.application_headers["Uint8_0"] = Uint8_0 + message_properties.application_headers["Uint8_max"] = Uint8_max + message_properties.application_headers["Uint16_0"] = Uint16_0 + message_properties.application_headers["Uint16_max"] = Uint16_max + message_properties.application_headers["Uint32_0"] = Uint32_0 + message_properties.application_headers["Uint32_max"] = Uint32_max + message_properties.application_headers["Uint64_0"] = Uint64_0 +# message_properties.application_headers["Uint64_max"] = Uint64_max + message_properties.application_headers["Int8_min"] = Int8_min + message_properties.application_headers["Int8_0"] = Int8_0 + message_properties.application_headers["Int8_max"] = Int8_max + message_properties.application_headers["Int16_min"] = Int16_min + message_properties.application_headers["Int16_0"] = Int16_0 + message_properties.application_headers["Int16_max"] = Int16_max + message_properties.application_headers["Int32_min"] = Int32_min + message_properties.application_headers["Int32_0"] = Int32_0 + message_properties.application_headers["Int32_max"] = Int32_max + message_properties.application_headers["Int64_min"] = Int64_min + message_properties.application_headers["Int64_0"] = Int64_0 + message_properties.application_headers["Int64_max"] = Int64_max + + message_properties.application_headers["Float_pi"] = Float_pi + message_properties.application_headers["Float_neg"] = Float_neg + message_properties.application_headers["Float_big"] = Float_big + message_properties.application_headers["Float_small"] = Float_small + message_properties.application_headers["Float_neg0"] = Float_neg0 + message_properties.application_headers["Float_pos0"] = Float_pos0 + message_properties.application_headers["Float_INF"] = Float_INF + message_properties.application_headers["Float_Negative_INF"] = Float_Negative_INF + + message_properties.application_headers["Double_pi"] = Double_pi + message_properties.application_headers["Double_neg"] = Double_neg + message_properties.application_headers["Double_big"] = Double_big + message_properties.application_headers["Double_small"] = Double_small + message_properties.application_headers["Double_neg0"] = Double_neg0 + message_properties.application_headers["Double_pos0"] = Double_pos0 + message_properties.application_headers["Double_INF"] = Double_INF + message_properties.application_headers["Double_Negative_INF"] = Double_Negative_INF + + message_properties.application_headers["char_1byte"] = char_1byte + message_properties.application_headers["char_2byte"] = char_2byte + message_properties.application_headers["char_3byte"] = char_3byte + message_properties.application_headers["char_4byte"] = char_4byte + + message_properties.application_headers["timestamp"] = timestamp + message_properties.application_headers["UUID"] = uuid4() + message_properties.application_headers["String_Greek"] = String_Greek + message_properties.application_headers["String_Empty"] = String_Empty + +def check_message(message): + +# message_properties = message.message_properties() + message_properties = message.get("message_properties") + assert message_properties.application_headers["void"] == None + assert message_properties.application_headers["boolean_true"] == boolean_true + assert message_properties.application_headers["boolean_false"] == boolean_false + assert message_properties.application_headers["Uint8_0"] == Uint8_0 + assert message_properties.application_headers["Uint8_max"] == Uint8_max + assert message_properties.application_headers["Uint16_0"] == Uint16_0 + assert message_properties.application_headers["Uint16_max"] == Uint16_max + assert message_properties.application_headers["Uint32_0"] == Uint32_0 + assert message_properties.application_headers["Uint32_max"] == Uint32_max + assert message_properties.application_headers["Uint64_0"] == Uint64_0 +# assert message_properties.application_headers["Uint64_max"] == Uint64_max + assert message_properties.application_headers["Int8_min"] == Int8_min + assert message_properties.application_headers["Int8_0"] == Int8_0 + assert message_properties.application_headers["Int8_max"] == Int8_max + assert message_properties.application_headers["Int16_min"] == Int16_min + assert message_properties.application_headers["Int16_0"] == Int16_0 + assert message_properties.application_headers["Int16_max"] == Int16_max + assert message_properties.application_headers["Int32_min"] == Int32_min + assert message_properties.application_headers["Int32_0"] == Int32_0 + assert message_properties.application_headers["Int32_max"] == Int32_max + assert message_properties.application_headers["Int64_min"] == Int64_min + assert message_properties.application_headers["Int64_0"] == Int64_0 + assert message_properties.application_headers["Int64_max"] == Int64_max + +# Change floating point comparisons to allow inexactness + + assert near_enough(message_properties.application_headers["Float_pi"], Float_pi, 0.00001) + assert near_enough(message_properties.application_headers["Float_neg"], Float_neg, 0.00001) + assert near_enough(message_properties.application_headers["Float_big"], Float_big, Float_big/1000000) + assert near_enough(message_properties.application_headers["Float_small"], Float_small, 0.00001) + assert message_properties.application_headers["Float_neg0"] == Float_neg0 + assert message_properties.application_headers["Float_pos0"] == Float_pos0 + assert message_properties.application_headers["Float_INF"] == Float_INF + assert message_properties.application_headers["Float_Negative_INF"] == Float_Negative_INF + + assert near_enough(message_properties.application_headers["Double_pi"], Double_pi, 0.00001) + assert near_enough(message_properties.application_headers["Double_neg"], Double_neg, 0.00001) + assert near_enough(message_properties.application_headers["Double_big"], Double_big, Double_big/1000000) + assert near_enough(message_properties.application_headers["Double_small"], Double_small, 0.00001) + assert message_properties.application_headers["Double_neg0"] == Double_neg0 + assert message_properties.application_headers["Double_pos0"] == Double_pos0 + assert message_properties.application_headers["Double_INF"] == Double_INF + assert message_properties.application_headers["Double_Negative_INF"] == Double_Negative_INF + + assert message_properties.application_headers["char_1byte"] == char_1byte + assert message_properties.application_headers["char_2byte"] == char_2byte + assert message_properties.application_headers["char_3byte"] == char_3byte + assert message_properties.application_headers["char_4byte"] == char_4byte + +# assert message_properties.application_headers["timestamp"] == timestamp +# assert message_properties.application_headers["UUID"] == UUID + assert message_properties.application_headers["String_Greek"] == String_Greek + assert message_properties.application_headers["String_Empty"] == String_Empty + + diff --git a/qpid/python/examples/datatypes/verify b/qpid/python/examples/datatypes/verify new file mode 100644 index 0000000000..cdc41b454e --- /dev/null +++ b/qpid/python/examples/datatypes/verify @@ -0,0 +1,24 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify +background "Request server running" ./server.py +clients ./client.py +kill %% # Must kill the server. +outputs "./client.py.out" " server.py.out" -- cgit v1.2.1 From 32d5fef50b5995378abb6459133460ffddf66ea4 Mon Sep 17 00:00:00 2001 From: Jonathan Robie Date: Fri, 13 Mar 2009 20:20:29 +0000 Subject: Removing the verify script - it breaks builds. Will restore when fixed. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@753381 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/datatypes/verify | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 qpid/python/examples/datatypes/verify (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/datatypes/verify b/qpid/python/examples/datatypes/verify deleted file mode 100644 index cdc41b454e..0000000000 --- a/qpid/python/examples/datatypes/verify +++ /dev/null @@ -1,24 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -background "Request server running" ./server.py -clients ./client.py -kill %% # Must kill the server. -outputs "./client.py.out" " server.py.out" -- cgit v1.2.1 From e125a6217f854f145f266f774741b9a654d60c2a Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Sun, 11 Oct 2009 16:59:06 +0000 Subject: added ping and drain examples for the new API git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@824108 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/api/drain | 62 ++++++++++++++++++++++++++++++++++ qpid/python/examples/api/ping | 76 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100755 qpid/python/examples/api/drain create mode 100755 qpid/python/examples/api/ping (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/api/drain b/qpid/python/examples/api/drain new file mode 100755 index 0000000000..485985f16d --- /dev/null +++ b/qpid/python/examples/api/drain @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +import optparse +from qpid.messaging import * +from qpid.util import URL + +parser = optparse.OptionParser(usage="usage: %prog [options] ADDRESS ...", + description="Drain messages from the supplied address.") +parser.add_option("-b", "--broker", default="localhost", + help="connect to specified BROKER (default %default)") +parser.add_option("-t", "--timeout", type=float, default=0, + help="timeout in seconds to wait before exiting (default %default)") +parser.add_option("-f", "--forever", action="store_true", + help="ignore timeout and wait forever") + +opts, args = parser.parse_args() + +url = URL(opts.broker) +if args: + addr = args.pop(0) +else: + parser.error("address is required") +if opts.forever: + timeout = None +else: + timeout = opts.timeout + +# XXX: should make URL default the port for us +conn = Connection.open(url.host, url.port or AMQP_PORT, + username=url.user, password=url.password) +ssn = conn.session() +rcv = ssn.receiver(addr) + +while True: + try: + print rcv.fetch(timeout=timeout) + ssn.acknowledge() + except Empty: + break + except ReceiveError, e: + print e + break + +conn.close() diff --git a/qpid/python/examples/api/ping b/qpid/python/examples/api/ping new file mode 100755 index 0000000000..59b367cca6 --- /dev/null +++ b/qpid/python/examples/api/ping @@ -0,0 +1,76 @@ +#!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +import optparse, time +from qpid.messaging import * +from qpid.util import URL + +parser = optparse.OptionParser(usage="usage: %prog [options] ADDRESS [ CONTENT ... ]", + description="Drain messages from the supplied address.") +parser.add_option("-b", "--broker", default="localhost", + help="connect to specified BROKER (default %default)") +parser.add_option("-c", "--count", type=int, default=1, + help="stop after count messages have been sent, zero disables (default %default)") +parser.add_option("-t", "--timeout", type=float, default=None, + help="exit after the specified time") +parser.add_option("-m", "--map", action="store_true", + help="interpret content as map") +parser.add_option("-i", "--id", help="use the supplied id instead of generating one") + +opts, args = parser.parse_args() + +url = URL(opts.broker) +if opts.id is None: + ping_id = str(uuid4()) +else: + ping_id = opts.id +if args: + addr = args.pop(0) +else: + parser.error("address is required") +if args: + content = " ".join(args) + if opts.map: + content = eval(content) +else: + content = None + +# XXX: should make URL default the port for us +conn = Connection.open(url.host, url.port or AMQP_PORT, + username=url.user, password=url.password) +ssn = conn.session() +snd = ssn.sender(addr) + +count = 0 +start = time.time() +while (opts.count == 0 or count < opts.count) and \ + (opts.timeout is None or time.time() - start < opts.timeout): + msg = Message(content) + msg.properties["ping-id"] = "%s:%s" % (ping_id, count) + + try: + snd.send(msg) + count += 1 + print msg + except SendError, e: + print e + break + +conn.close() -- cgit v1.2.1 From b2524e1641ea2d424545162c5fdb1629edbb5aba Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Sun, 11 Oct 2009 20:39:01 +0000 Subject: added ability to specify reply-to and message properties for ping; also added server example git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@824145 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/api/ping | 41 +++++++++++++++++---- qpid/python/examples/api/server | 80 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 7 deletions(-) create mode 100755 qpid/python/examples/api/server (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/api/ping b/qpid/python/examples/api/ping index 59b367cca6..7d3686e7cf 100755 --- a/qpid/python/examples/api/ping +++ b/qpid/python/examples/api/ping @@ -22,6 +22,16 @@ import optparse, time from qpid.messaging import * from qpid.util import URL +def nameval(st): + idx = st.find("=") + if idx >= 0: + name = st[0:idx] + value = st[idx+1:] + else: + name = st + value = None + return name, value + parser = optparse.OptionParser(usage="usage: %prog [options] ADDRESS [ CONTENT ... ]", description="Drain messages from the supplied address.") parser.add_option("-b", "--broker", default="localhost", @@ -30,9 +40,12 @@ parser.add_option("-c", "--count", type=int, default=1, help="stop after count messages have been sent, zero disables (default %default)") parser.add_option("-t", "--timeout", type=float, default=None, help="exit after the specified time") -parser.add_option("-m", "--map", action="store_true", - help="interpret content as map") parser.add_option("-i", "--id", help="use the supplied id instead of generating one") +parser.add_option("-r", "--reply-to", help="specify reply-to address") +parser.add_option("-P", "--property", dest="properties", action="append", default=[], + help="specify message property") +parser.add_option("-M", "--map", dest="entries", action="append", default=[], + help="specify map entry for message body") opts, args = parser.parse_args() @@ -45,12 +58,23 @@ if args: addr = args.pop(0) else: parser.error("address is required") + +content = None + if args: - content = " ".join(args) - if opts.map: - content = eval(content) + text = " ".join(args) +else: + text = None + +if opts.entries: + content = {} + if text: + content["text"] = text + for e in opts.entries: + name, val = nameval(e) + content[name] = val else: - content = None + content = text # XXX: should make URL default the port for us conn = Connection.open(url.host, url.port or AMQP_PORT, @@ -62,8 +86,11 @@ count = 0 start = time.time() while (opts.count == 0 or count < opts.count) and \ (opts.timeout is None or time.time() - start < opts.timeout): - msg = Message(content) + msg = Message(content, reply_to=opts.reply_to) msg.properties["ping-id"] = "%s:%s" % (ping_id, count) + for p in opts.properties: + name, val = nameval(p) + msg.properties[name] = val try: snd.send(msg) diff --git a/qpid/python/examples/api/server b/qpid/python/examples/api/server new file mode 100755 index 0000000000..4e986f5ac8 --- /dev/null +++ b/qpid/python/examples/api/server @@ -0,0 +1,80 @@ +#!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +import optparse, sys, traceback +from qpid.messaging import * +from qpid.util import URL +from subprocess import Popen, STDOUT, PIPE + +parser = optparse.OptionParser(usage="usage: %prog [options] ADDRESS ...", + description="handle requests from the supplied address.") +parser.add_option("-b", "--broker", default="localhost", + help="connect to specified BROKER (default %default)") + +opts, args = parser.parse_args() + +url = URL(opts.broker) +if args: + addr = args.pop(0) +else: + parser.error("address is required") + +# XXX: should make URL default the port for us +conn = Connection.open(url.host, url.port or AMQP_PORT, + username=url.user, password=url.password) +conn.reconnect = True +ssn = conn.session() +rcv = ssn.receiver(addr) + +def dispatch(msg): + msg_type = msg.properties.get("type") + if msg_type == "shell": + proc = Popen(msg.content, shell=True, stderr=STDOUT, stdin=PIPE, stdout=PIPE) + output, _ = proc.communicate() + result = Message(output) + result.properties["exit"] = proc.returncode + elif msg_type == "eval": + try: + content = eval(msg.content) + except: + content = traceback.format_exc() + result = Message(content) + else: + result = Message("unrecognized message type: %s" % msg_type) + return result + +while True: + try: + msg = rcv.fetch() + response = dispatch(msg) + snd = ssn.sender(msg.reply_to) + try: + snd.send(response) + except SendError, e: + print e + snd.close() + ssn.acknowledge() + except Empty: + break + except ReceiveError, e: + print e + break + +conn.close() -- cgit v1.2.1 From eef12c6a8f8d62747b2dfa933fef7838e656fc59 Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Mon, 12 Oct 2009 11:19:09 +0000 Subject: added an option for logging git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@824297 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/api/server | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/api/server b/qpid/python/examples/api/server index 4e986f5ac8..adb2dcf792 100755 --- a/qpid/python/examples/api/server +++ b/qpid/python/examples/api/server @@ -22,14 +22,21 @@ import optparse, sys, traceback from qpid.messaging import * from qpid.util import URL from subprocess import Popen, STDOUT, PIPE +from qpid.log import enable, DEBUG, WARN parser = optparse.OptionParser(usage="usage: %prog [options] ADDRESS ...", description="handle requests from the supplied address.") parser.add_option("-b", "--broker", default="localhost", help="connect to specified BROKER (default %default)") +parser.add_option("-v", dest="verbose", action="store_true", help="enable logging") opts, args = parser.parse_args() +if opts.verbose: + enable("qpid", DEBUG) +else: + enable("qpid", WARN) + url = URL(opts.broker) if args: addr = args.pop(0) -- cgit v1.2.1 From dee4bfc330263cd8f60aed63098eebb3f1ca57ca Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Mon, 12 Oct 2009 14:34:42 +0000 Subject: renamed ping to spout git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@824361 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/api/ping | 103 ----------------------------------------- qpid/python/examples/api/spout | 103 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 103 deletions(-) delete mode 100755 qpid/python/examples/api/ping create mode 100755 qpid/python/examples/api/spout (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/api/ping b/qpid/python/examples/api/ping deleted file mode 100755 index 7d3686e7cf..0000000000 --- a/qpid/python/examples/api/ping +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env python -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -import optparse, time -from qpid.messaging import * -from qpid.util import URL - -def nameval(st): - idx = st.find("=") - if idx >= 0: - name = st[0:idx] - value = st[idx+1:] - else: - name = st - value = None - return name, value - -parser = optparse.OptionParser(usage="usage: %prog [options] ADDRESS [ CONTENT ... ]", - description="Drain messages from the supplied address.") -parser.add_option("-b", "--broker", default="localhost", - help="connect to specified BROKER (default %default)") -parser.add_option("-c", "--count", type=int, default=1, - help="stop after count messages have been sent, zero disables (default %default)") -parser.add_option("-t", "--timeout", type=float, default=None, - help="exit after the specified time") -parser.add_option("-i", "--id", help="use the supplied id instead of generating one") -parser.add_option("-r", "--reply-to", help="specify reply-to address") -parser.add_option("-P", "--property", dest="properties", action="append", default=[], - help="specify message property") -parser.add_option("-M", "--map", dest="entries", action="append", default=[], - help="specify map entry for message body") - -opts, args = parser.parse_args() - -url = URL(opts.broker) -if opts.id is None: - ping_id = str(uuid4()) -else: - ping_id = opts.id -if args: - addr = args.pop(0) -else: - parser.error("address is required") - -content = None - -if args: - text = " ".join(args) -else: - text = None - -if opts.entries: - content = {} - if text: - content["text"] = text - for e in opts.entries: - name, val = nameval(e) - content[name] = val -else: - content = text - -# XXX: should make URL default the port for us -conn = Connection.open(url.host, url.port or AMQP_PORT, - username=url.user, password=url.password) -ssn = conn.session() -snd = ssn.sender(addr) - -count = 0 -start = time.time() -while (opts.count == 0 or count < opts.count) and \ - (opts.timeout is None or time.time() - start < opts.timeout): - msg = Message(content, reply_to=opts.reply_to) - msg.properties["ping-id"] = "%s:%s" % (ping_id, count) - for p in opts.properties: - name, val = nameval(p) - msg.properties[name] = val - - try: - snd.send(msg) - count += 1 - print msg - except SendError, e: - print e - break - -conn.close() diff --git a/qpid/python/examples/api/spout b/qpid/python/examples/api/spout new file mode 100755 index 0000000000..c78c13524d --- /dev/null +++ b/qpid/python/examples/api/spout @@ -0,0 +1,103 @@ +#!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +import optparse, time +from qpid.messaging import * +from qpid.util import URL + +def nameval(st): + idx = st.find("=") + if idx >= 0: + name = st[0:idx] + value = st[idx+1:] + else: + name = st + value = None + return name, value + +parser = optparse.OptionParser(usage="usage: %prog [options] ADDRESS [ CONTENT ... ]", + description="Drain messages from the supplied address.") +parser.add_option("-b", "--broker", default="localhost", + help="connect to specified BROKER (default %default)") +parser.add_option("-c", "--count", type=int, default=1, + help="stop after count messages have been sent, zero disables (default %default)") +parser.add_option("-t", "--timeout", type=float, default=None, + help="exit after the specified time") +parser.add_option("-i", "--id", help="use the supplied id instead of generating one") +parser.add_option("-r", "--reply-to", help="specify reply-to address") +parser.add_option("-P", "--property", dest="properties", action="append", default=[], + help="specify message property") +parser.add_option("-M", "--map", dest="entries", action="append", default=[], + help="specify map entry for message body") + +opts, args = parser.parse_args() + +url = URL(opts.broker) +if opts.id is None: + spout_id = str(uuid4()) +else: + spout_id = opts.id +if args: + addr = args.pop(0) +else: + parser.error("address is required") + +content = None + +if args: + text = " ".join(args) +else: + text = None + +if opts.entries: + content = {} + if text: + content["text"] = text + for e in opts.entries: + name, val = nameval(e) + content[name] = val +else: + content = text + +# XXX: should make URL default the port for us +conn = Connection.open(url.host, url.port or AMQP_PORT, + username=url.user, password=url.password) +ssn = conn.session() +snd = ssn.sender(addr) + +count = 0 +start = time.time() +while (opts.count == 0 or count < opts.count) and \ + (opts.timeout is None or time.time() - start < opts.timeout): + msg = Message(content, reply_to=opts.reply_to) + msg.properties["spout-id"] = "%s:%s" % (spout_id, count) + for p in opts.properties: + name, val = nameval(p) + msg.properties[name] = val + + try: + snd.send(msg) + count += 1 + print msg + except SendError, e: + print e + break + +conn.close() -- cgit v1.2.1 From 97eb8787eb76d6ad76d0a29a9fff2f3cc9af76f4 Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Mon, 12 Oct 2009 14:47:48 +0000 Subject: fixed the usage text git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@824366 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/api/spout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/api/spout b/qpid/python/examples/api/spout index c78c13524d..6a9b2b6e3d 100755 --- a/qpid/python/examples/api/spout +++ b/qpid/python/examples/api/spout @@ -33,7 +33,7 @@ def nameval(st): return name, value parser = optparse.OptionParser(usage="usage: %prog [options] ADDRESS [ CONTENT ... ]", - description="Drain messages from the supplied address.") + description="Send messages to the supplied address.") parser.add_option("-b", "--broker", default="localhost", help="connect to specified BROKER (default %default)") parser.add_option("-c", "--count", type=int, default=1, -- cgit v1.2.1 From fb61c034f8dd85ed3317b6fa6b701947502a7cfb Mon Sep 17 00:00:00 2001 From: Ted Ross Date: Tue, 8 Dec 2009 15:56:20 +0000 Subject: QPID-2249 Python Headers Exchange Example git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@888452 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/README | 52 +++++++++++ qpid/python/examples/headers/declare_queues.py | 77 ++++++++++++++++ qpid/python/examples/headers/headers_consumer.py | 107 +++++++++++++++++++++++ qpid/python/examples/headers/headers_producer.py | 79 +++++++++++++++++ qpid/python/examples/headers/verify | 22 +++++ qpid/python/examples/headers/verify.in | 25 ++++++ 6 files changed, 362 insertions(+) create mode 100755 qpid/python/examples/headers/declare_queues.py create mode 100755 qpid/python/examples/headers/headers_consumer.py create mode 100755 qpid/python/examples/headers/headers_producer.py create mode 100644 qpid/python/examples/headers/verify create mode 100644 qpid/python/examples/headers/verify.in (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/README b/qpid/python/examples/README index 24d449afc2..bd30b2a6f4 100644 --- a/qpid/python/examples/README +++ b/qpid/python/examples/README @@ -265,3 +265,55 @@ You should see the following output: 1670 35 + +Running the Headers Examples +----------------------------- + +To run the headers examples, do the following: + +1. Make sure that a qpidd broker is running: + + $ ps -eaf | grep qpidd + + If a broker is running, you should see the qpidd process in the output of the above command. + +2.Declare a message queues and bind them to an exchange by running declare_queues.py, as follows: + + $ python declare_queues.py + + This program has no output. After this program has been run, all messages sent to the amq.match exchange with an application-header of {'class': 'first'} will be routed to the queue named "first" and messages with an application-header of {'class': 'second'} will be routed to the queue named "second". + +3.Publish a series of messages to the amq.match exchange by running headers_producer.py, as follows: + + $ python headers_producer.py + +This program has no output; the messages are routed to the message queues, as instructed by the bindings. + +4. Read the messages from the message queues using headers_consumer.py as follows: + + $ python headers_consumer.py + +You should see the following output: + +message(first) 0 +message(first) 1 +message(first) 2 +message(first) 3 +message(first) 4 +message(first) 5 +message(first) 6 +message(first) 7 +message(first) 8 +message(first) 9 +That's all, folks! +message(second) 0 +message(second) 1 +message(second) 2 +message(second) 3 +message(second) 4 +message(second) 5 +message(second) 6 +message(second) 7 +message(second) 8 +message(second) 9 +That's all, folks! diff --git a/qpid/python/examples/headers/declare_queues.py b/qpid/python/examples/headers/declare_queues.py new file mode 100755 index 0000000000..b3d5c43fe5 --- /dev/null +++ b/qpid/python/examples/headers/declare_queues.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +""" + declare_queues.py + + Creates and binds a queue on an AMQP headers exchange. + + All messages with an application header of {'class': 'first'} are sent to queue "first". + All messages with an application header of {'class': 'second'} are sent to queue "second". +""" + +# Common includes + +import qpid +import sys +import os +from qpid.util import connect +from qpid.connection import Connection +from qpid.datatypes import Message, RangedSet, uuid4 +from qpid.queue import Empty + +#----- Initialization ----------------------------------- + +# Set parameters for login + +host="127.0.0.1" +port=5672 +user="guest" +password="guest" + +# If an alternate host or port has been specified, use that instead +# (this is used in our unit tests) +if len(sys.argv) > 1 : + host=sys.argv[1] +if len(sys.argv) > 2 : + port=int(sys.argv[2]) + +# Create a connection. +socket = connect(host, port) +connection = Connection (sock=socket, username=user, password=password) +connection.start() +session = connection.session(str(uuid4())) + +#----- Create queues ------------------------------------- + +# queue_declare() creates an AMQP queue, which is held +# on the broker. Published messages are sent to the AMQP queue, +# from which messages are delivered to consumers. +# +# exchange_bind() determines which messages are routed to a queue. + +session.queue_declare(queue="first") +session.exchange_bind(exchange="amq.match", queue="first", arguments={'x-match':'any', 'class':'first'}) + +session.queue_declare(queue="second") +session.exchange_bind(exchange="amq.match", queue="second", arguments={'x-match':'any', 'class':'second'}) + +#----- Cleanup --------------------------------------------- + +session.close(timeout=10) diff --git a/qpid/python/examples/headers/headers_consumer.py b/qpid/python/examples/headers/headers_consumer.py new file mode 100755 index 0000000000..8f5ce3c5ff --- /dev/null +++ b/qpid/python/examples/headers/headers_consumer.py @@ -0,0 +1,107 @@ +#!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +""" + headers_consumer.py + + This AMQP client reads messages from two message + queues named "first" and "second". +""" + +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, RangedSet, uuid4 +from qpid.queue import Empty + + +#----- Initialization -------------------------------------- + +# Set parameters for login + +host="127.0.0.1" +port=5672 +user="guest" +password="guest" + +# If an alternate host or port has been specified, use that instead +# (this is used in our unit tests) +if len(sys.argv) > 1 : + host=sys.argv[1] +if len(sys.argv) > 2 : + port=int(sys.argv[2]) + +# Create a connection. +socket = connect(host, port) +connection = Connection (sock=socket, username=user, password=password) +connection.start() +session = connection.session(str(uuid4())) + +#----- Read from queue -------------------------------------------- + +# Now let's create two local client queues and tell them to read +# incoming messages. + +# The consumer tag identifies the client-side queue. + +local_queue_name_first = "local_queue_first" +local_queue_name_second = "local_queue_second" + +queue_first = session.incoming(local_queue_name_first) +queue_second = session.incoming(local_queue_name_second) + +# Call message_subscribe() to tell the broker to deliver messages +# from the AMQP queue to these local client queues. The broker will +# start delivering messages as soon as credit is allocated using +# queue.start(). + +session.message_subscribe(queue="first", destination=local_queue_name_first) +session.message_subscribe(queue="second", destination=local_queue_name_second) + +queue_first.start() +queue_second.start() + +# Initialize 'final' and 'content', variables used to identify the last message. + +final = "That's all, folks!" # In a message body, signals the last message +content = "" # Content of the last message read + +message = None +while content != final: + message = queue_first.get(timeout=10) + content = message.body + session.message_accept(RangedSet(message.id)) + print content + +content = "" +while content != final: + message = queue_second.get(timeout=10) + content = message.body + session.message_accept(RangedSet(message.id)) + print content + +#----- Cleanup ------------------------------------------------ + +# Clean up before exiting so there are no open threads. +# + +session.close(timeout=10) diff --git a/qpid/python/examples/headers/headers_producer.py b/qpid/python/examples/headers/headers_producer.py new file mode 100755 index 0000000000..43130d5993 --- /dev/null +++ b/qpid/python/examples/headers/headers_producer.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +""" + headers_producer.py + + Publishes messages to an AMQP headers exchange, using + various application header values. +""" + +import qpid +import sys +import os +from qpid.util import connect +from qpid.connection import Connection +from qpid.datatypes import Message +from qpid.datatypes import uuid4 +from qpid.queue import Empty + + +#----- Initialization ----------------------------------- + +# Set parameters for login + +host="127.0.0.1" +port=5672 +user="guest" +password="guest" + +# If an alternate host or port has been specified, use that instead +# (this is used in our unit tests) +if len(sys.argv) > 1 : + host=sys.argv[1] +if len(sys.argv) > 2 : + port=int(sys.argv[2]) + +# Create a connection. +socket = connect(host, port) +connection = Connection (sock=socket, username=user, password=password) +connection.start() +session = connection.session(str(uuid4())) + +#----- Publish some messages ------------------------------ + +# Create some messages and put them on the broker. +props_first = session.message_properties(application_headers={'class':'first'}) +props_second = session.message_properties(application_headers={'class':'second'}) +props_third = session.message_properties(application_headers={'class':'third'}) + +for i in range(10): + session.message_transfer(destination="amq.match", message=Message(props_first,"message(first) " + str(i))) + session.message_transfer(destination="amq.match", message=Message(props_second,"message(second) " + str(i))) + session.message_transfer(destination="amq.match", message=Message(props_third,"message(third) " + str(i))) + +session.message_transfer(destination="amq.match", message=Message(props_first,"That's all, folks!")) +session.message_transfer(destination="amq.match", message=Message(props_second,"That's all, folks!")) +session.message_transfer(destination="amq.match", message=Message(props_third,"That's all, folks!")) + +#----- Cleanup -------------------------------------------- + +# Clean up before exiting so there are no open threads. + +session.close(timeout=10) diff --git a/qpid/python/examples/headers/verify b/qpid/python/examples/headers/verify new file mode 100644 index 0000000000..5fe96c5c23 --- /dev/null +++ b/qpid/python/examples/headers/verify @@ -0,0 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify +clients ./declare_queues.py ./headers_producer.py ./headers_consumer.py +outputs ./declare_queues.py.out ./headers_producer.py.out ./headers_consumer.py.out diff --git a/qpid/python/examples/headers/verify.in b/qpid/python/examples/headers/verify.in new file mode 100644 index 0000000000..90ffd0a071 --- /dev/null +++ b/qpid/python/examples/headers/verify.in @@ -0,0 +1,25 @@ +==== declare_queues.py.out +==== headers_producer.py.out +==== headers_consumer.py.out +message(first) 0 +message(first) 1 +message(first) 2 +message(first) 3 +message(first) 4 +message(first) 5 +message(first) 6 +message(first) 7 +message(first) 8 +message(first) 9 +That's all, folks! +message(second) 0 +message(second) 1 +message(second) 2 +message(second) 3 +message(second) 4 +message(second) 5 +message(second) 6 +message(second) 7 +message(second) 8 +message(second) 9 +That's all, folks! -- cgit v1.2.1 From 9cb7a14f8860b166799dee312aeaf7897fdc3edb Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Tue, 5 Jan 2010 18:19:37 +0000 Subject: merged documentation and address changes from rnr branch git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@896159 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/api/spout | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/api/spout b/qpid/python/examples/api/spout index 6a9b2b6e3d..1928303e43 100755 --- a/qpid/python/examples/api/spout +++ b/qpid/python/examples/api/spout @@ -43,8 +43,9 @@ parser.add_option("-t", "--timeout", type=float, default=None, parser.add_option("-i", "--id", help="use the supplied id instead of generating one") parser.add_option("-r", "--reply-to", help="specify reply-to address") parser.add_option("-P", "--property", dest="properties", action="append", default=[], - help="specify message property") + metavar="NAME=VALUE", help="specify message property") parser.add_option("-M", "--map", dest="entries", action="append", default=[], + metavar="KEY=VALUE", help="specify map entry for message body") opts, args = parser.parse_args() -- cgit v1.2.1 From e651a3846f8d610201e6e81f59e225bbfd8b6e7b Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Fri, 29 Jan 2010 21:41:46 +0000 Subject: added reconnect_delay, reconnect_limit, and backups option to Connection git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@904634 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/api/drain | 20 +++++++++++++++++++- qpid/python/examples/api/server | 16 +++++++++++++--- qpid/python/examples/api/spout | 22 ++++++++++++++++++++-- 3 files changed, 52 insertions(+), 6 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/api/drain b/qpid/python/examples/api/drain index 485985f16d..ef1f050c8c 100755 --- a/qpid/python/examples/api/drain +++ b/qpid/python/examples/api/drain @@ -21,18 +21,32 @@ import optparse from qpid.messaging import * from qpid.util import URL +from qpid.log import enable, DEBUG, WARN parser = optparse.OptionParser(usage="usage: %prog [options] ADDRESS ...", description="Drain messages from the supplied address.") parser.add_option("-b", "--broker", default="localhost", help="connect to specified BROKER (default %default)") +parser.add_option("-r", "--reconnect", action="store_true", + help="enable auto reconnect") +parser.add_option("-d", "--reconnect-delay", type=float, default=3, + help="delay between reconnect attempts") +parser.add_option("-l", "--reconnect-limit", type=int, + help="maximum number of reconnect attempts") parser.add_option("-t", "--timeout", type=float, default=0, help="timeout in seconds to wait before exiting (default %default)") parser.add_option("-f", "--forever", action="store_true", help="ignore timeout and wait forever") +parser.add_option("-v", dest="verbose", action="store_true", + help="enable logging") opts, args = parser.parse_args() +if opts.verbose: + enable("qpid", DEBUG) +else: + enable("qpid", WARN) + url = URL(opts.broker) if args: addr = args.pop(0) @@ -45,7 +59,11 @@ else: # XXX: should make URL default the port for us conn = Connection.open(url.host, url.port or AMQP_PORT, - username=url.user, password=url.password) + username=url.user, + password=url.password, + reconnect=opts.reconnect, + reconnect_delay=opts.reconnect_delay, + reconnect_limit=opts.reconnect_limit) ssn = conn.session() rcv = ssn.receiver(addr) diff --git a/qpid/python/examples/api/server b/qpid/python/examples/api/server index adb2dcf792..a9cd8579e3 100755 --- a/qpid/python/examples/api/server +++ b/qpid/python/examples/api/server @@ -28,7 +28,14 @@ parser = optparse.OptionParser(usage="usage: %prog [options] ADDRESS ...", description="handle requests from the supplied address.") parser.add_option("-b", "--broker", default="localhost", help="connect to specified BROKER (default %default)") -parser.add_option("-v", dest="verbose", action="store_true", help="enable logging") +parser.add_option("-r", "--reconnect", action="store_true", + help="enable auto reconnect") +parser.add_option("-d", "--reconnect-delay", type=float, default=3, + help="delay between reconnect attempts") +parser.add_option("-l", "--reconnect-limit", type=int, + help="maximum number of reconnect attempts") +parser.add_option("-v", dest="verbose", action="store_true", + help="enable logging") opts, args = parser.parse_args() @@ -45,8 +52,11 @@ else: # XXX: should make URL default the port for us conn = Connection.open(url.host, url.port or AMQP_PORT, - username=url.user, password=url.password) -conn.reconnect = True + username=url.user, + password=url.password, + reconnect=opts.reconnect, + reconnect_delay=opts.reconnect_delay, + reconnect_limit=opts.reconnect_limit) ssn = conn.session() rcv = ssn.receiver(addr) diff --git a/qpid/python/examples/api/spout b/qpid/python/examples/api/spout index 1928303e43..ad98c486fd 100755 --- a/qpid/python/examples/api/spout +++ b/qpid/python/examples/api/spout @@ -21,6 +21,7 @@ import optparse, time from qpid.messaging import * from qpid.util import URL +from qpid.log import enable, DEBUG, WARN def nameval(st): idx = st.find("=") @@ -36,20 +37,33 @@ parser = optparse.OptionParser(usage="usage: %prog [options] ADDRESS [ CONTENT . description="Send messages to the supplied address.") parser.add_option("-b", "--broker", default="localhost", help="connect to specified BROKER (default %default)") +parser.add_option("-r", "--reconnect", action="store_true", + help="enable auto reconnect") +parser.add_option("-d", "--reconnect-delay", type=float, default=3, + help="delay between reconnect attempts") +parser.add_option("-l", "--reconnect-limit", type=int, + help="maximum number of reconnect attempts") parser.add_option("-c", "--count", type=int, default=1, help="stop after count messages have been sent, zero disables (default %default)") parser.add_option("-t", "--timeout", type=float, default=None, help="exit after the specified time") parser.add_option("-i", "--id", help="use the supplied id instead of generating one") -parser.add_option("-r", "--reply-to", help="specify reply-to address") +parser.add_option("-R", "--reply-to", help="specify reply-to address") parser.add_option("-P", "--property", dest="properties", action="append", default=[], metavar="NAME=VALUE", help="specify message property") parser.add_option("-M", "--map", dest="entries", action="append", default=[], metavar="KEY=VALUE", help="specify map entry for message body") +parser.add_option("-v", dest="verbose", action="store_true", + help="enable logging") opts, args = parser.parse_args() +if opts.verbose: + enable("qpid", DEBUG) +else: + enable("qpid", WARN) + url = URL(opts.broker) if opts.id is None: spout_id = str(uuid4()) @@ -79,7 +93,11 @@ else: # XXX: should make URL default the port for us conn = Connection.open(url.host, url.port or AMQP_PORT, - username=url.user, password=url.password) + username=url.user, + password=url.password, + reconnect=opts.reconnect, + reconnect_delay=opts.reconnect_delay, + reconnect_limit=opts.reconnect_limit) ssn = conn.session() snd = ssn.sender(addr) -- cgit v1.2.1 From e217dad606f1acf8e9ccd11fcbc832681b17737d Mon Sep 17 00:00:00 2001 From: Ted Ross Date: Mon, 1 Feb 2010 16:02:41 +0000 Subject: Added missing binding_key values to the headers bindings. This allows the bindings to be later deleted. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@905316 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/headers/declare_queues.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/headers/declare_queues.py b/qpid/python/examples/headers/declare_queues.py index b3d5c43fe5..e976f71e55 100755 --- a/qpid/python/examples/headers/declare_queues.py +++ b/qpid/python/examples/headers/declare_queues.py @@ -67,10 +67,10 @@ session = connection.session(str(uuid4())) # exchange_bind() determines which messages are routed to a queue. session.queue_declare(queue="first") -session.exchange_bind(exchange="amq.match", queue="first", arguments={'x-match':'any', 'class':'first'}) +session.exchange_bind(exchange="amq.match", queue="first", binding_key="first", arguments={'x-match':'any', 'class':'first'}) session.queue_declare(queue="second") -session.exchange_bind(exchange="amq.match", queue="second", arguments={'x-match':'any', 'class':'second'}) +session.exchange_bind(exchange="amq.match", queue="second", binding_key="second", arguments={'x-match':'any', 'class':'second'}) #----- Cleanup --------------------------------------------- -- cgit v1.2.1 From 8618b7e45ba6b0f74b27c68d2bcf94cd57f15758 Mon Sep 17 00:00:00 2001 From: Rajith Muditha Attapattu Date: Fri, 12 Feb 2010 22:30:38 +0000 Subject: I have added the license header to the files included in this commit. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@909641 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/datatypes/testdata.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/datatypes/testdata.py b/qpid/python/examples/datatypes/testdata.py index cdf140d400..251872ff52 100644 --- a/qpid/python/examples/datatypes/testdata.py +++ b/qpid/python/examples/datatypes/testdata.py @@ -1,3 +1,24 @@ +# +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# + # -*- encoding: utf-8 -*- from qpid.datatypes import uuid4, timestamp -- cgit v1.2.1 From 7dc632ea602acd17665ae4e64008da555d095f10 Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Sat, 13 Feb 2010 13:02:06 +0000 Subject: added count and print formatting options to drain git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@909810 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/api/drain | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/api/drain b/qpid/python/examples/api/drain index ef1f050c8c..a852d29de7 100755 --- a/qpid/python/examples/api/drain +++ b/qpid/python/examples/api/drain @@ -27,6 +27,10 @@ parser = optparse.OptionParser(usage="usage: %prog [options] ADDRESS ...", description="Drain messages from the supplied address.") parser.add_option("-b", "--broker", default="localhost", help="connect to specified BROKER (default %default)") +parser.add_option("-c", "--count", type=int, + help="number of messages to drain") +parser.add_option("-f", "--forever", action="store_true", + help="ignore timeout and wait forever") parser.add_option("-r", "--reconnect", action="store_true", help="enable auto reconnect") parser.add_option("-d", "--reconnect-delay", type=float, default=3, @@ -35,8 +39,8 @@ parser.add_option("-l", "--reconnect-limit", type=int, help="maximum number of reconnect attempts") parser.add_option("-t", "--timeout", type=float, default=0, help="timeout in seconds to wait before exiting (default %default)") -parser.add_option("-f", "--forever", action="store_true", - help="ignore timeout and wait forever") +parser.add_option("-p", "--print", dest="format", default="%(M)s", + help="format string for printing messages (default %default)") parser.add_option("-v", dest="verbose", action="store_true", help="enable logging") @@ -57,6 +61,17 @@ if opts.forever: else: timeout = opts.timeout +class Formatter: + + def __init__(self, message): + self.message = message + self.environ = {"M": self.message, + "P": self.message.properties, + "C": self.message.content} + + def __getitem__(self, st): + return eval(st, self.environ) + # XXX: should make URL default the port for us conn = Connection.open(url.host, url.port or AMQP_PORT, username=url.user, @@ -67,9 +82,12 @@ conn = Connection.open(url.host, url.port or AMQP_PORT, ssn = conn.session() rcv = ssn.receiver(addr) -while True: +count = 0 +while not opts.count or count < opts.count: try: - print rcv.fetch(timeout=timeout) + msg = rcv.fetch(timeout=timeout) + print opts.format % Formatter(msg) + count += 1 ssn.acknowledge() except Empty: break -- cgit v1.2.1 From 02336adf2b3ce963fcd6db9ecb1cb6397ed2fc47 Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Sat, 13 Feb 2010 13:24:52 +0000 Subject: handle Control-C git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@909811 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/api/drain | 44 +++++++++++++++++++---------------- qpid/python/examples/api/spout | 52 +++++++++++++++++++++++------------------- 2 files changed, 52 insertions(+), 44 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/api/drain b/qpid/python/examples/api/drain index a852d29de7..f2d7a50058 100755 --- a/qpid/python/examples/api/drain +++ b/qpid/python/examples/api/drain @@ -73,26 +73,30 @@ class Formatter: return eval(st, self.environ) # XXX: should make URL default the port for us -conn = Connection.open(url.host, url.port or AMQP_PORT, - username=url.user, - password=url.password, - reconnect=opts.reconnect, - reconnect_delay=opts.reconnect_delay, - reconnect_limit=opts.reconnect_limit) -ssn = conn.session() -rcv = ssn.receiver(addr) +conn = Connection(url.host, url.port or AMQP_PORT, + username=url.user, + password=url.password, + reconnect=opts.reconnect, + reconnect_delay=opts.reconnect_delay, + reconnect_limit=opts.reconnect_limit) +try: + conn.connect() + ssn = conn.session() + rcv = ssn.receiver(addr) -count = 0 -while not opts.count or count < opts.count: - try: - msg = rcv.fetch(timeout=timeout) - print opts.format % Formatter(msg) - count += 1 - ssn.acknowledge() - except Empty: - break - except ReceiveError, e: - print e - break + count = 0 + while not opts.count or count < opts.count: + try: + msg = rcv.fetch(timeout=timeout) + print opts.format % Formatter(msg) + count += 1 + ssn.acknowledge() + except Empty: + break + except ReceiveError, e: + print e + break +except KeyboardInterrupt: + pass conn.close() diff --git a/qpid/python/examples/api/spout b/qpid/python/examples/api/spout index ad98c486fd..97cb540c21 100755 --- a/qpid/python/examples/api/spout +++ b/qpid/python/examples/api/spout @@ -92,31 +92,35 @@ else: content = text # XXX: should make URL default the port for us -conn = Connection.open(url.host, url.port or AMQP_PORT, - username=url.user, - password=url.password, - reconnect=opts.reconnect, - reconnect_delay=opts.reconnect_delay, - reconnect_limit=opts.reconnect_limit) -ssn = conn.session() -snd = ssn.sender(addr) +conn = Connection(url.host, url.port or AMQP_PORT, + username=url.user, + password=url.password, + reconnect=opts.reconnect, + reconnect_delay=opts.reconnect_delay, + reconnect_limit=opts.reconnect_limit) +try: + conn.connect() + ssn = conn.session() + snd = ssn.sender(addr) -count = 0 -start = time.time() -while (opts.count == 0 or count < opts.count) and \ - (opts.timeout is None or time.time() - start < opts.timeout): - msg = Message(content, reply_to=opts.reply_to) - msg.properties["spout-id"] = "%s:%s" % (spout_id, count) - for p in opts.properties: - name, val = nameval(p) - msg.properties[name] = val + count = 0 + start = time.time() + while (opts.count == 0 or count < opts.count) and \ + (opts.timeout is None or time.time() - start < opts.timeout): + msg = Message(content, reply_to=opts.reply_to) + msg.properties["spout-id"] = "%s:%s" % (spout_id, count) + for p in opts.properties: + name, val = nameval(p) + msg.properties[name] = val - try: - snd.send(msg) - count += 1 - print msg - except SendError, e: - print e - break + try: + snd.send(msg) + count += 1 + print msg + except SendError, e: + print e + break +except KeyboardInterrupt: + pass conn.close() -- cgit v1.2.1 From 1f0c6b6661d511d5858e3755718750a5e6fc70f8 Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Tue, 16 Feb 2010 03:48:44 +0000 Subject: changed sender/receiver to be synchronous by default when invoked on a connected session git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@910388 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/api/drain | 5 ++--- qpid/python/examples/api/server | 38 ++++++++++++++++++++------------------ qpid/python/examples/api/spout | 12 +++++------- 3 files changed, 27 insertions(+), 28 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/api/drain b/qpid/python/examples/api/drain index f2d7a50058..c244cbc09c 100755 --- a/qpid/python/examples/api/drain +++ b/qpid/python/examples/api/drain @@ -93,9 +93,8 @@ try: ssn.acknowledge() except Empty: break - except ReceiveError, e: - print e - break +except ReceiveError, e: + print e except KeyboardInterrupt: pass diff --git a/qpid/python/examples/api/server b/qpid/python/examples/api/server index a9cd8579e3..d7cd53de4b 100755 --- a/qpid/python/examples/api/server +++ b/qpid/python/examples/api/server @@ -51,15 +51,12 @@ else: parser.error("address is required") # XXX: should make URL default the port for us -conn = Connection.open(url.host, url.port or AMQP_PORT, - username=url.user, - password=url.password, - reconnect=opts.reconnect, - reconnect_delay=opts.reconnect_delay, - reconnect_limit=opts.reconnect_limit) -ssn = conn.session() -rcv = ssn.receiver(addr) - +conn = Connection(url.host, url.port or AMQP_PORT, + username=url.user, + password=url.password, + reconnect=opts.reconnect, + reconnect_delay=opts.reconnect_delay, + reconnect_limit=opts.reconnect_limit) def dispatch(msg): msg_type = msg.properties.get("type") if msg_type == "shell": @@ -77,21 +74,26 @@ def dispatch(msg): result = Message("unrecognized message type: %s" % msg_type) return result -while True: - try: +try: + conn.connect() + ssn = conn.session() + rcv = ssn.receiver(addr) + + while True: msg = rcv.fetch() response = dispatch(msg) - snd = ssn.sender(msg.reply_to) + snd = None try: + snd = ssn.sender(msg.reply_to) snd.send(response) except SendError, e: print e - snd.close() + if snd is not None: + snd.close() ssn.acknowledge() - except Empty: - break - except ReceiveError, e: - print e - break +except ReceiveError, e: + print e +except KeyboardInterrupt: + pass conn.close() diff --git a/qpid/python/examples/api/spout b/qpid/python/examples/api/spout index 97cb540c21..5479b66211 100755 --- a/qpid/python/examples/api/spout +++ b/qpid/python/examples/api/spout @@ -113,13 +113,11 @@ try: name, val = nameval(p) msg.properties[name] = val - try: - snd.send(msg) - count += 1 - print msg - except SendError, e: - print e - break + snd.send(msg) + count += 1 + print msg +except SendError, e: + print e except KeyboardInterrupt: pass -- cgit v1.2.1 From 6c2a7ea80b9cabbd9c9051e2d5c9f4274451ed7f Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Wed, 17 Feb 2010 16:13:12 +0000 Subject: added reservations to examples git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@911048 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/reservations/common.py | 86 ++++++++++ qpid/python/examples/reservations/inventory | 100 ++++++++++++ qpid/python/examples/reservations/machine-agent | 109 +++++++++++++ qpid/python/examples/reservations/reserve | 200 ++++++++++++++++++++++++ 4 files changed, 495 insertions(+) create mode 100644 qpid/python/examples/reservations/common.py create mode 100755 qpid/python/examples/reservations/inventory create mode 100755 qpid/python/examples/reservations/machine-agent create mode 100755 qpid/python/examples/reservations/reserve (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/reservations/common.py b/qpid/python/examples/reservations/common.py new file mode 100644 index 0000000000..4f9efd0227 --- /dev/null +++ b/qpid/python/examples/reservations/common.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +import traceback +from fnmatch import fnmatch +from qpid.messaging import * + +class Dispatcher: + + def unhandled(self, msg): + print "UNHANDLED MESSAGE: %s" % msg + + def ignored(self, msg): + return False + + def dispatch(self, msg): + try: + if self.ignored(msg): + return () + else: + type = msg.properties.get("type") + replies = getattr(self, "do_%s" % type, self.unhandled)(msg) + if replies is None: + return () + else: + return replies + except: + traceback.print_exc() + return () + + def run(self, session): + senders = {} + while self.running(): + msg = session.next_receiver().fetch() + replies = self.dispatch(msg) + + count = len(replies) + sequence = 1 + for r in replies: + if senders.has_key(r.to): + rsnd = senders[r.to] + else: + rsnd = session.sender(r.to) + senders[r.to] = rsnd + + r.correlation_id = msg.correlation_id + r.properties["count"] = count + r.properties["sequence"] = sequence + sequence += 1 + try: + rsnd.send(r) + except SendError, e: + print e + del senders[r.to] + rsnd.close() + + session.acknowledge(msg) + +def get_status(msg): + return msg.content["identity"], msg.content["status"], msg.content["owner"] + +FREE = "free" +BUSY = "busy" + +def match(value, patterns): + for p in patterns: + if fnmatch(value, p): + return True + return False diff --git a/qpid/python/examples/reservations/inventory b/qpid/python/examples/reservations/inventory new file mode 100755 index 0000000000..10c2034efc --- /dev/null +++ b/qpid/python/examples/reservations/inventory @@ -0,0 +1,100 @@ +#!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +import optparse, traceback +from qpid.messaging import * +from qpid.util import URL +from qpid.log import enable, DEBUG, WARN +from common import * + +parser = optparse.OptionParser(usage="usage: %prog [options]", + description="machine inventory agent") +parser.add_option("-b", "--broker", default="localhost", + help="connect to specified BROKER (default %default)") +parser.add_option("-d", "--database", + help="database file for persistent machine status") +parser.add_option("-a", "--address", default="reservations", + help="address for reservation requests") +parser.add_option("-v", dest="verbose", action="store_true", + help="enable verbose logging") + +opts, args = parser.parse_args() + +if opts.verbose: + enable("qpid", DEBUG) +else: + enable("qpid", WARN) + +url = URL(opts.broker) +conn = Connection.open(url.host, url.port or AMQP_PORT, + username=url.user, password=url.password, + reconnect=True, + reconnect_delay=1) + +class Inventory(Dispatcher): + + def __init__(self): + self.agents = {} + + def running(self): + return True + + def do_status(self, msg): + id, status, owner = get_status(msg) + self.agents[id] = (status, owner) + + def do_query(self, msg): + patterns = msg.content["identity"] + result = [] + for id, (status, owner) in self.agents.items(): + if match(id, patterns): + r = Message(to = msg.reply_to, + properties = { + "type": "status" + }, + content = { + "identity": id, + "status": status, + "owner": owner + }) + result.append(r) + continue + if not result: + result.append(Message(to = msg.reply_to, + properties = {"type": "empty"})) + return result + + def ignored(self, msg): + type = msg.properties.get("type") + return type not in ("status", "query") + +try: + ssn = conn.session() + rcv = ssn.receiver(opts.address, capacity = 10) + snd = ssn.sender(opts.address) + snd.send(Message(reply_to = opts.address, + properties = {"type": "discover", "identity": ["*"]})) + + inv = Inventory() + inv.run(ssn) +except KeyboardInterrupt: + pass +finally: + conn.close() diff --git a/qpid/python/examples/reservations/machine-agent b/qpid/python/examples/reservations/machine-agent new file mode 100755 index 0000000000..9df663bdf5 --- /dev/null +++ b/qpid/python/examples/reservations/machine-agent @@ -0,0 +1,109 @@ +#!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +import optparse, socket +from qpid.messaging import * +from qpid.util import URL +from qpid.log import enable, DEBUG, WARN +from common import * + +host = socket.gethostname() + +parser = optparse.OptionParser(usage="usage: %prog [options]", + description="machine reservation agent") +parser.add_option("-b", "--broker", default="localhost", + help="connect to specified BROKER (default %default)") +parser.add_option("-d", "--database", + help="database file for persistent machine status") +parser.add_option("-a", "--address", default="reservations", + help="address for reservation requests") +parser.add_option("-i", "--identity", default=host, + help="resource id (default %default)") +parser.add_option("-v", dest="verbose", action="store_true", + help="enable verbose logging") + +opts, args = parser.parse_args() + +if opts.verbose: + enable("qpid", DEBUG) +else: + enable("qpid", WARN) + +url = URL(opts.broker) +conn = Connection.open(url.host, url.port or AMQP_PORT, + username=url.user, password=url.password, + reconnect=True, + reconnect_delay=1) + + +class Agent(Dispatcher): + + def __init__(self, identity): + self.identity = identity + self.status = FREE + self.owner = None + + def running(self): + return True + + def get_status(self): + msg = Message(properties = {"type": "status"}, + content = {"identity": self.identity, + "status": self.status, + "owner": self.owner}) + return msg + + def do_discover(self, msg): + r = self.get_status() + r.to = msg.reply_to + return [r] + + def do_reserve(self, msg): + if self.status == FREE: + self.owner = msg.content["owner"] + self.status = BUSY + return self.do_discover(msg) + + def do_release(self, msg): + if self.owner == msg.content["owner"]: + self.status = FREE + self.owner = None + return self.do_discover(msg) + + def ignored(self, msg): + patterns = msg.properties.get("identity") + type = msg.properties.get("type") + if patterns and match(self.identity, patterns): + return type == "status" + else: + return True + +try: + ssn = conn.session() + rcv = ssn.receiver(opts.address) + rcv.capacity = 10 + snd = ssn.sender(opts.address) + agent = Agent(opts.identity) + snd.send(agent.get_status()) + agent.run(ssn) +except KeyboardInterrupt: + pass +finally: + conn.close() diff --git a/qpid/python/examples/reservations/reserve b/qpid/python/examples/reservations/reserve new file mode 100755 index 0000000000..cabc103c77 --- /dev/null +++ b/qpid/python/examples/reservations/reserve @@ -0,0 +1,200 @@ +#!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +import optparse, os, sys, time +from uuid import uuid4 +from qpid.messaging import * +from qpid.util import URL +from qpid.log import enable, DEBUG, WARN +from common import * + +parser = optparse.OptionParser(usage="usage: %prog [options] PATTERN ...", + description="reserve a machine") +parser.add_option("-b", "--broker", default="localhost", + help="connect to specified BROKER (default %default)") +parser.add_option("-a", "--address", default="reservations", + help="address for reservation requests") +parser.add_option("-r", "--release", action="store_true", + help="release any machines matching the pattern") +parser.add_option("-s", "--status", action="store_true", + help="list machine status") +parser.add_option("-d", "--discover", action="store_true", + help="use discovery instead of inventory") +parser.add_option("-o", "--owner", default=os.environ["USER"], + help="the holder of the reservation") +parser.add_option("-n", "--number", type=int, default=1, + help="the number of machines to reserve") +parser.add_option("-t", "--timeout", type=float, default=10, + help="timeout in seconds to wait for resources") +parser.add_option("-v", dest="verbose", action="store_true", + help="enable verbose logging") + +opts, args = parser.parse_args() + +if opts.verbose: + enable("qpid", DEBUG) +else: + enable("qpid", WARN) + +if args: + patterns = args +else: + patterns = ["*"] + +url = URL(opts.broker) +conn = Connection.open(url.host, url.port or AMQP_PORT, + username=url.user, password=url.password) + +if opts.release: + request_type = "release" + candidate_status = BUSY + candidate_owner = opts.owner +else: + request_type = "reserve" + candidate_status = FREE + candidate_owner = None + +class Requester(Dispatcher): + + def __init__(self): + self.agents = {} + self.requests = set() + self.outstanding = set() + + def agent_status(self, id): + status, owner = self.agents[id] + if owner: + return "%s %s(%s)" % (id, status, owner) + else: + return "%s %s" % (id, status) + + def correlation(self, cid): + self.requests.add(cid) + self.outstanding.add(cid) + + def ignored(self, msg): + return msg.properties.get("type") not in ("status", "empty") or \ + msg.correlation_id not in self.requests + + def do_status(self, msg): + id, status, owner = get_status(msg) + self.agents[id] = (status, owner) + + if opts.status: + print self.agent_status(id) + + def do_empty(self, msg): + print "no matching resources" + + def candidates(self, candidate_status, candidate_owner): + for id, (status, owner) in self.agents.items(): + if status == candidate_status and owner == candidate_owner: + yield id + + def dispatch(self, msg): + result = Dispatcher.dispatch(self, msg) + count = msg.properties.get("count") + sequence = msg.properties.get("sequence") + if count and sequence == count: + self.outstanding.discard(msg.correlation_id) + return result + +try: + ssn = conn.session() + rcv = ssn.receiver(opts.address, capacity=10) + snd = ssn.sender(opts.address) + + correlation_id = str(uuid4()) + + if opts.discover: + properties = {"type": "discover", "identity": patterns} + content = None + else: + properties = {"type": "query"} + content = {"identity": patterns} + + snd.send(Message(reply_to = opts.address, + correlation_id = correlation_id, + properties = properties, + content = content)) + + req = Requester() + req.correlation(correlation_id) + + start = time.time() + ellapsed = 0 + requested = set() + discovering = opts.discover + + while ellapsed <= opts.timeout and (discovering or req.outstanding): + try: + msg = rcv.fetch(opts.timeout - ellapsed) + ssn.acknowledge(msg) + except Empty: + continue + finally: + ellapsed = time.time() - start + + req.dispatch(msg) + if not opts.status: + if len(requested) < opts.number: + for cid in req.candidates(candidate_status, candidate_owner): + if cid in requested: continue + req_msg = Message(reply_to = opts.address, + correlation_id = str(uuid4()), + properties = {"type": request_type, + "identity": [cid]}, + content = {"owner": opts.owner}) + if not requested: + print "requesting %s:" % request_type, + print cid, + sys.stdout.flush() + req.correlation(req_msg.correlation_id) + snd.send(req_msg) + requested.add(cid) + else: + discovering = False + + if requested: + print + owners = {} + for id in requested: + st, ow = req.agents[id] + if not owners.has_key(ow): + owners[ow] = [] + owners[ow].append(id) + keys = list(owners.keys()) + keys.sort() + for k in keys: + owners[k].sort() + v = ", ".join(owners[k]) + if k is None: + print "free: %s" % v + else: + print "owner %s: %s" % (k, v) + elif req.agents and not opts.status: + print "no available resources" + + if req.outstanding: + print "request timed out" +except KeyboardInterrupt: + pass +finally: + conn.close() -- cgit v1.2.1 From ad2598d3f13f64d1ab9dc9dfc1eb17394a625d15 Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Wed, 17 Feb 2010 17:58:23 +0000 Subject: removed sender caching as this should now be unnecessary git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@911121 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/reservations/common.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/reservations/common.py b/qpid/python/examples/reservations/common.py index 4f9efd0227..24e64beda4 100644 --- a/qpid/python/examples/reservations/common.py +++ b/qpid/python/examples/reservations/common.py @@ -46,7 +46,6 @@ class Dispatcher: return () def run(self, session): - senders = {} while self.running(): msg = session.next_receiver().fetch() replies = self.dispatch(msg) @@ -54,22 +53,17 @@ class Dispatcher: count = len(replies) sequence = 1 for r in replies: - if senders.has_key(r.to): - rsnd = senders[r.to] - else: - rsnd = session.sender(r.to) - senders[r.to] = rsnd - r.correlation_id = msg.correlation_id r.properties["count"] = count r.properties["sequence"] = sequence sequence += 1 try: - rsnd.send(r) + snd = session.sender(r.to) + snd.send(r) except SendError, e: print e - del senders[r.to] - rsnd.close() + finally: + snd.close() session.acknowledge(msg) -- cgit v1.2.1 From a753a0f8d2770b7400664898cec598db618f01e0 Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Wed, 17 Feb 2010 20:06:44 +0000 Subject: added a subject option to spout git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@911163 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/api/spout | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/api/spout b/qpid/python/examples/api/spout index 5479b66211..9606c3501f 100755 --- a/qpid/python/examples/api/spout +++ b/qpid/python/examples/api/spout @@ -48,6 +48,7 @@ parser.add_option("-c", "--count", type=int, default=1, parser.add_option("-t", "--timeout", type=float, default=None, help="exit after the specified time") parser.add_option("-i", "--id", help="use the supplied id instead of generating one") +parser.add_option("-S", "--subject", help="specify a subject") parser.add_option("-R", "--reply-to", help="specify reply-to address") parser.add_option("-P", "--property", dest="properties", action="append", default=[], metavar="NAME=VALUE", help="specify message property") @@ -107,7 +108,9 @@ try: start = time.time() while (opts.count == 0 or count < opts.count) and \ (opts.timeout is None or time.time() - start < opts.timeout): - msg = Message(content, reply_to=opts.reply_to) + msg = Message(subject=opts.subject, + reply_to=opts.reply_to, + content=content) msg.properties["spout-id"] = "%s:%s" % (spout_id, count) for p in opts.properties: name, val = nameval(p) -- cgit v1.2.1 From 1ed642bc5fc90709604e2f5f12b3358e7070dbb5 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Wed, 10 Mar 2010 11:48:20 +0000 Subject: QPID-2441: patch from Jan Sarenik that prevents verification failures when running the examples if locale is not as expected git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@921319 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/pubsub/verify.in | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/pubsub/verify.in b/qpid/python/examples/pubsub/verify.in index 1b74acd832..ac1506b324 100644 --- a/qpid/python/examples/pubsub/verify.in +++ b/qpid/python/examples/pubsub/verify.in @@ -1,5 +1,18 @@ ==== topic_publisher.py.out ==== topic_subscriber.py.out | remove_uuid | sort +Messages on 'europe' queue: +Messages on 'news' queue: +Messages on 'usa' queue: +Messages on 'weather' queue: +Queues created - please start the topic producer +Subscribing local queue 'local_europe' to europe-' +Subscribing local queue 'local_news' to news-' +Subscribing local queue 'local_usa' to usa-' +Subscribing local queue 'local_weather' to weather-' +That's all, folks! +That's all, folks! +That's all, folks! +That's all, folks! europe.news 0 europe.news 0 europe.news 1 @@ -20,19 +33,6 @@ europe.weather 3 europe.weather 3 europe.weather 4 europe.weather 4 -Messages on 'europe' queue: -Messages on 'news' queue: -Messages on 'usa' queue: -Messages on 'weather' queue: -Queues created - please start the topic producer -Subscribing local queue 'local_europe' to europe-' -Subscribing local queue 'local_news' to news-' -Subscribing local queue 'local_usa' to usa-' -Subscribing local queue 'local_weather' to weather-' -That's all, folks! -That's all, folks! -That's all, folks! -That's all, folks! usa.news 0 usa.news 0 usa.news 1 -- cgit v1.2.1 From 30ff4dcc85eaf5a2ea52cad9d965086c8062a4ce Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Wed, 31 Mar 2010 21:17:09 +0000 Subject: added SSL support to API git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@929717 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/api/drain | 2 +- qpid/python/examples/api/server | 2 +- qpid/python/examples/api/spout | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/api/drain b/qpid/python/examples/api/drain index c244cbc09c..d7ac03afa6 100755 --- a/qpid/python/examples/api/drain +++ b/qpid/python/examples/api/drain @@ -73,7 +73,7 @@ class Formatter: return eval(st, self.environ) # XXX: should make URL default the port for us -conn = Connection(url.host, url.port or AMQP_PORT, +conn = Connection(url.host, url.port, username=url.user, password=url.password, reconnect=opts.reconnect, diff --git a/qpid/python/examples/api/server b/qpid/python/examples/api/server index d7cd53de4b..f0bf1c2a4b 100755 --- a/qpid/python/examples/api/server +++ b/qpid/python/examples/api/server @@ -51,7 +51,7 @@ else: parser.error("address is required") # XXX: should make URL default the port for us -conn = Connection(url.host, url.port or AMQP_PORT, +conn = Connection(url.host, url.port, username=url.user, password=url.password, reconnect=opts.reconnect, diff --git a/qpid/python/examples/api/spout b/qpid/python/examples/api/spout index 9606c3501f..0d37ede512 100755 --- a/qpid/python/examples/api/spout +++ b/qpid/python/examples/api/spout @@ -93,7 +93,7 @@ else: content = text # XXX: should make URL default the port for us -conn = Connection(url.host, url.port or AMQP_PORT, +conn = Connection(url.host, url.port, username=url.user, password=url.password, reconnect=opts.reconnect, -- cgit v1.2.1 From a807cbe0a5b732225f8a2f3a9a4357f0fe5a3ddd Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Thu, 1 Apr 2010 20:39:31 +0000 Subject: updated reconnect option names to match C++ API git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@930084 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/api/drain | 6 +++--- qpid/python/examples/api/server | 6 +++--- qpid/python/examples/api/spout | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/api/drain b/qpid/python/examples/api/drain index d7ac03afa6..372426c801 100755 --- a/qpid/python/examples/api/drain +++ b/qpid/python/examples/api/drain @@ -33,8 +33,8 @@ parser.add_option("-f", "--forever", action="store_true", help="ignore timeout and wait forever") parser.add_option("-r", "--reconnect", action="store_true", help="enable auto reconnect") -parser.add_option("-d", "--reconnect-delay", type=float, default=3, - help="delay between reconnect attempts") +parser.add_option("-i", "--reconnect-interval", type=float, default=3, + help="interval between reconnect attempts") parser.add_option("-l", "--reconnect-limit", type=int, help="maximum number of reconnect attempts") parser.add_option("-t", "--timeout", type=float, default=0, @@ -77,7 +77,7 @@ conn = Connection(url.host, url.port, username=url.user, password=url.password, reconnect=opts.reconnect, - reconnect_delay=opts.reconnect_delay, + reconnect_interval=opts.reconnect_interval, reconnect_limit=opts.reconnect_limit) try: conn.connect() diff --git a/qpid/python/examples/api/server b/qpid/python/examples/api/server index f0bf1c2a4b..3103dd795a 100755 --- a/qpid/python/examples/api/server +++ b/qpid/python/examples/api/server @@ -30,8 +30,8 @@ parser.add_option("-b", "--broker", default="localhost", help="connect to specified BROKER (default %default)") parser.add_option("-r", "--reconnect", action="store_true", help="enable auto reconnect") -parser.add_option("-d", "--reconnect-delay", type=float, default=3, - help="delay between reconnect attempts") +parser.add_option("-i", "--reconnect-interval", type=float, default=3, + help="interval between reconnect attempts") parser.add_option("-l", "--reconnect-limit", type=int, help="maximum number of reconnect attempts") parser.add_option("-v", dest="verbose", action="store_true", @@ -55,7 +55,7 @@ conn = Connection(url.host, url.port, username=url.user, password=url.password, reconnect=opts.reconnect, - reconnect_delay=opts.reconnect_delay, + reconnect_interval=opts.reconnect_interval, reconnect_limit=opts.reconnect_limit) def dispatch(msg): msg_type = msg.properties.get("type") diff --git a/qpid/python/examples/api/spout b/qpid/python/examples/api/spout index 0d37ede512..9e5759b2dd 100755 --- a/qpid/python/examples/api/spout +++ b/qpid/python/examples/api/spout @@ -39,15 +39,15 @@ parser.add_option("-b", "--broker", default="localhost", help="connect to specified BROKER (default %default)") parser.add_option("-r", "--reconnect", action="store_true", help="enable auto reconnect") -parser.add_option("-d", "--reconnect-delay", type=float, default=3, - help="delay between reconnect attempts") +parser.add_option("-i", "--reconnect-interval", type=float, default=3, + help="interval between reconnect attempts") parser.add_option("-l", "--reconnect-limit", type=int, help="maximum number of reconnect attempts") parser.add_option("-c", "--count", type=int, default=1, help="stop after count messages have been sent, zero disables (default %default)") parser.add_option("-t", "--timeout", type=float, default=None, help="exit after the specified time") -parser.add_option("-i", "--id", help="use the supplied id instead of generating one") +parser.add_option("-I", "--id", help="use the supplied id instead of generating one") parser.add_option("-S", "--subject", help="specify a subject") parser.add_option("-R", "--reply-to", help="specify reply-to address") parser.add_option("-P", "--property", dest="properties", action="append", default=[], @@ -97,7 +97,7 @@ conn = Connection(url.host, url.port, username=url.user, password=url.password, reconnect=opts.reconnect, - reconnect_delay=opts.reconnect_delay, + reconnect_interval=opts.reconnect_interval, reconnect_limit=opts.reconnect_limit) try: conn.connect() -- cgit v1.2.1 From 5e0d449d9de02b4937747cc0b67cf50e62310b81 Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Fri, 9 Apr 2010 10:54:07 +0000 Subject: Changes to connection lifecycle methods and Connection parameters: - Connection.open -> Connection.establish - Connection.connect() split into Connection.open(), Connection.attach() - Connection.disconnect() -> Connection.detach() - reconnect_hosts -> reconnect_urls - transport now takes tcp, ssl, and tcp+tls git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@932352 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/api/drain | 8 ++------ qpid/python/examples/api/server | 8 ++------ qpid/python/examples/api/spout | 8 ++------ 3 files changed, 6 insertions(+), 18 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/api/drain b/qpid/python/examples/api/drain index 372426c801..a2e40ec8a0 100755 --- a/qpid/python/examples/api/drain +++ b/qpid/python/examples/api/drain @@ -51,7 +51,6 @@ if opts.verbose: else: enable("qpid", WARN) -url = URL(opts.broker) if args: addr = args.pop(0) else: @@ -72,15 +71,12 @@ class Formatter: def __getitem__(self, st): return eval(st, self.environ) -# XXX: should make URL default the port for us -conn = Connection(url.host, url.port, - username=url.user, - password=url.password, +conn = Connection(opts.broker, reconnect=opts.reconnect, reconnect_interval=opts.reconnect_interval, reconnect_limit=opts.reconnect_limit) try: - conn.connect() + conn.open() ssn = conn.session() rcv = ssn.receiver(addr) diff --git a/qpid/python/examples/api/server b/qpid/python/examples/api/server index 3103dd795a..0500e6f380 100755 --- a/qpid/python/examples/api/server +++ b/qpid/python/examples/api/server @@ -44,16 +44,12 @@ if opts.verbose: else: enable("qpid", WARN) -url = URL(opts.broker) if args: addr = args.pop(0) else: parser.error("address is required") -# XXX: should make URL default the port for us -conn = Connection(url.host, url.port, - username=url.user, - password=url.password, +conn = Connection(opts.broker, reconnect=opts.reconnect, reconnect_interval=opts.reconnect_interval, reconnect_limit=opts.reconnect_limit) @@ -75,7 +71,7 @@ def dispatch(msg): return result try: - conn.connect() + conn.open() ssn = conn.session() rcv = ssn.receiver(addr) diff --git a/qpid/python/examples/api/spout b/qpid/python/examples/api/spout index 9e5759b2dd..dacebb5d1a 100755 --- a/qpid/python/examples/api/spout +++ b/qpid/python/examples/api/spout @@ -65,7 +65,6 @@ if opts.verbose: else: enable("qpid", WARN) -url = URL(opts.broker) if opts.id is None: spout_id = str(uuid4()) else: @@ -92,15 +91,12 @@ if opts.entries: else: content = text -# XXX: should make URL default the port for us -conn = Connection(url.host, url.port, - username=url.user, - password=url.password, +conn = Connection(opts.broker, reconnect=opts.reconnect, reconnect_interval=opts.reconnect_interval, reconnect_limit=opts.reconnect_limit) try: - conn.connect() + conn.open() ssn = conn.session() snd = ssn.sender(addr) -- cgit v1.2.1 From f328f8dfb20911b952f0c5551cc37c0b8d42576d Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Fri, 9 Apr 2010 15:14:27 +0000 Subject: updated reservations example to match latest changes git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@932454 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/reservations/common.py | 4 ++-- qpid/python/examples/reservations/inventory | 16 +++++----------- qpid/python/examples/reservations/machine-agent | 10 ++-------- qpid/python/examples/reservations/reserve | 5 +---- 4 files changed, 10 insertions(+), 25 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/reservations/common.py b/qpid/python/examples/reservations/common.py index 24e64beda4..12f07e1c92 100644 --- a/qpid/python/examples/reservations/common.py +++ b/qpid/python/examples/reservations/common.py @@ -52,13 +52,13 @@ class Dispatcher: count = len(replies) sequence = 1 - for r in replies: + for to, r in replies: r.correlation_id = msg.correlation_id r.properties["count"] = count r.properties["sequence"] = sequence sequence += 1 try: - snd = session.sender(r.to) + snd = session.sender(to) snd.send(r) except SendError, e: print e diff --git a/qpid/python/examples/reservations/inventory b/qpid/python/examples/reservations/inventory index 10c2034efc..0a49643e5f 100755 --- a/qpid/python/examples/reservations/inventory +++ b/qpid/python/examples/reservations/inventory @@ -20,7 +20,6 @@ import optparse, traceback from qpid.messaging import * -from qpid.util import URL from qpid.log import enable, DEBUG, WARN from common import * @@ -42,11 +41,7 @@ if opts.verbose: else: enable("qpid", WARN) -url = URL(opts.broker) -conn = Connection.open(url.host, url.port or AMQP_PORT, - username=url.user, password=url.password, - reconnect=True, - reconnect_delay=1) +conn = Connection.establish(opts.broker, reconnect=True, reconnect_interval=1) class Inventory(Dispatcher): @@ -65,8 +60,7 @@ class Inventory(Dispatcher): result = [] for id, (status, owner) in self.agents.items(): if match(id, patterns): - r = Message(to = msg.reply_to, - properties = { + r = Message(properties = { "type": "status" }, content = { @@ -74,11 +68,11 @@ class Inventory(Dispatcher): "status": status, "owner": owner }) - result.append(r) + result.append((msg.reply_to, r)) continue if not result: - result.append(Message(to = msg.reply_to, - properties = {"type": "empty"})) + result.append((msg.reply_to, + Message(properties = {"type": "empty"}))) return result def ignored(self, msg): diff --git a/qpid/python/examples/reservations/machine-agent b/qpid/python/examples/reservations/machine-agent index 9df663bdf5..a221a8b6de 100755 --- a/qpid/python/examples/reservations/machine-agent +++ b/qpid/python/examples/reservations/machine-agent @@ -20,7 +20,6 @@ import optparse, socket from qpid.messaging import * -from qpid.util import URL from qpid.log import enable, DEBUG, WARN from common import * @@ -46,11 +45,7 @@ if opts.verbose: else: enable("qpid", WARN) -url = URL(opts.broker) -conn = Connection.open(url.host, url.port or AMQP_PORT, - username=url.user, password=url.password, - reconnect=True, - reconnect_delay=1) +conn = Connection.establish(opts.broker, reconnect=True, reconnect_interval=1) class Agent(Dispatcher): @@ -72,8 +67,7 @@ class Agent(Dispatcher): def do_discover(self, msg): r = self.get_status() - r.to = msg.reply_to - return [r] + return [(msg.reply_to, r)] def do_reserve(self, msg): if self.status == FREE: diff --git a/qpid/python/examples/reservations/reserve b/qpid/python/examples/reservations/reserve index cabc103c77..68e7fee912 100755 --- a/qpid/python/examples/reservations/reserve +++ b/qpid/python/examples/reservations/reserve @@ -21,7 +21,6 @@ import optparse, os, sys, time from uuid import uuid4 from qpid.messaging import * -from qpid.util import URL from qpid.log import enable, DEBUG, WARN from common import * @@ -58,9 +57,7 @@ if args: else: patterns = ["*"] -url = URL(opts.broker) -conn = Connection.open(url.host, url.port or AMQP_PORT, - username=url.user, password=url.password) +conn = Connection.establish(opts.broker) if opts.release: request_type = "release" -- cgit v1.2.1 From 058db49b7c8fb61bba39042e38eecb3c1fe32da5 Mon Sep 17 00:00:00 2001 From: Jonathan Robie Date: Fri, 16 Apr 2010 01:46:24 +0000 Subject: Hello World example in Python - matches hello_world.cpp git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@934663 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/api/hello | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 qpid/python/examples/api/hello (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/api/hello b/qpid/python/examples/api/hello new file mode 100755 index 0000000000..4644189941 --- /dev/null +++ b/qpid/python/examples/api/hello @@ -0,0 +1,45 @@ +#!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +import sys +from qpid.messaging import * + +broker = "localhost:5672" if len(sys.argv)<2 else sys.argv[1] +address = "amq.topic" if len(sys.argv)<3 else sys.argv[2] + +connection = Connection(broker) + +try: + connection.open() + session = connection.session() + + sender = session.sender(address) + receiver = session.receiver(address) + + sender.send(Message("Hello world!")); + + message = receiver.fetch() + print message.content + session.acknowledge() + +except MessagingError,m: + print m +finally: + connection.close() -- cgit v1.2.1 From 0550140874c6dc9e0cdb132568d05b2bfe67449e Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Tue, 27 Apr 2010 16:37:38 +0000 Subject: correct name of exception to be caught git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@938550 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/api/drain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/api/drain b/qpid/python/examples/api/drain index a2e40ec8a0..eaf86f94ac 100755 --- a/qpid/python/examples/api/drain +++ b/qpid/python/examples/api/drain @@ -89,7 +89,7 @@ try: ssn.acknowledge() except Empty: break -except ReceiveError, e: +except ReceiverError, e: print e except KeyboardInterrupt: pass -- cgit v1.2.1 From e859587fe359eb41ba0fdb7d0ceba9b1e8b77b8d Mon Sep 17 00:00:00 2001 From: Jonathan Robie Date: Wed, 5 May 2010 21:22:14 +0000 Subject: XML Exchange example. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@941497 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/api/hello_xml | 77 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 qpid/python/examples/api/hello_xml (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/api/hello_xml b/qpid/python/examples/api/hello_xml new file mode 100755 index 0000000000..07c2b13120 --- /dev/null +++ b/qpid/python/examples/api/hello_xml @@ -0,0 +1,77 @@ +#!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +import sys +from qpid.messaging import * + +broker = "localhost:5672" +connection = Connection(broker) + +try: + connection.open() + session = connection.session() + +# Set up the receiver + query = """ + let $w := ./weather + return $w/station = 'Raleigh-Durham International Airport (KRDU)' + and $w/temperature_f > 50 + and $w/temperature_f - $w/dewpoint > 5 + and $w/wind_speed_mph > 7 + and $w/wind_speed_mph < 20 """ + +# query="./weather" + + address = """ + xml; { + create: always, + node:{ type: queue }, + link: { + x-bindings: [{ exchange: xml, key: weather, arguments: { xquery: %r} }] + } + } + """ % query + + receiver = session.receiver(address) + +# Send an observation + + observations = """ + + Raleigh-Durham International Airport (KRDU) + 16 + 70 + 35 + """ + + message = Message(subject="weather", content=observations) + sender = session.sender("xml") + sender.send(message) + +# Retrieve matching message from the receiver and print it + + message = receiver.fetch(timeout=1) + print message.content + session.acknowledge() + +except MessagingError,m: + print m +finally: + connection.close() -- cgit v1.2.1 From 4f7efe697023e9b654e5ceef9648204a322ce779 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Wed, 9 Jun 2010 15:37:02 +0000 Subject: Minor adjustment to option definitions for Python 2.3 git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@953044 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/api/drain | 8 ++++---- qpid/python/examples/api/server | 4 ++-- qpid/python/examples/api/spout | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/api/drain b/qpid/python/examples/api/drain index eaf86f94ac..5e30153bc2 100755 --- a/qpid/python/examples/api/drain +++ b/qpid/python/examples/api/drain @@ -27,17 +27,17 @@ parser = optparse.OptionParser(usage="usage: %prog [options] ADDRESS ...", description="Drain messages from the supplied address.") parser.add_option("-b", "--broker", default="localhost", help="connect to specified BROKER (default %default)") -parser.add_option("-c", "--count", type=int, +parser.add_option("-c", "--count", type="int", help="number of messages to drain") parser.add_option("-f", "--forever", action="store_true", help="ignore timeout and wait forever") parser.add_option("-r", "--reconnect", action="store_true", help="enable auto reconnect") -parser.add_option("-i", "--reconnect-interval", type=float, default=3, +parser.add_option("-i", "--reconnect-interval", type="float", default=3, help="interval between reconnect attempts") -parser.add_option("-l", "--reconnect-limit", type=int, +parser.add_option("-l", "--reconnect-limit", type="int", help="maximum number of reconnect attempts") -parser.add_option("-t", "--timeout", type=float, default=0, +parser.add_option("-t", "--timeout", type="float", default=0, help="timeout in seconds to wait before exiting (default %default)") parser.add_option("-p", "--print", dest="format", default="%(M)s", help="format string for printing messages (default %default)") diff --git a/qpid/python/examples/api/server b/qpid/python/examples/api/server index 0500e6f380..3b9a3560da 100755 --- a/qpid/python/examples/api/server +++ b/qpid/python/examples/api/server @@ -30,9 +30,9 @@ parser.add_option("-b", "--broker", default="localhost", help="connect to specified BROKER (default %default)") parser.add_option("-r", "--reconnect", action="store_true", help="enable auto reconnect") -parser.add_option("-i", "--reconnect-interval", type=float, default=3, +parser.add_option("-i", "--reconnect-interval", type="float", default=3, help="interval between reconnect attempts") -parser.add_option("-l", "--reconnect-limit", type=int, +parser.add_option("-l", "--reconnect-limit", type="int", help="maximum number of reconnect attempts") parser.add_option("-v", dest="verbose", action="store_true", help="enable logging") diff --git a/qpid/python/examples/api/spout b/qpid/python/examples/api/spout index dacebb5d1a..c2dc4db380 100755 --- a/qpid/python/examples/api/spout +++ b/qpid/python/examples/api/spout @@ -39,13 +39,13 @@ parser.add_option("-b", "--broker", default="localhost", help="connect to specified BROKER (default %default)") parser.add_option("-r", "--reconnect", action="store_true", help="enable auto reconnect") -parser.add_option("-i", "--reconnect-interval", type=float, default=3, +parser.add_option("-i", "--reconnect-interval", type="float", default=3, help="interval between reconnect attempts") -parser.add_option("-l", "--reconnect-limit", type=int, +parser.add_option("-l", "--reconnect-limit", type="int", help="maximum number of reconnect attempts") -parser.add_option("-c", "--count", type=int, default=1, +parser.add_option("-c", "--count", type="int", default=1, help="stop after count messages have been sent, zero disables (default %default)") -parser.add_option("-t", "--timeout", type=float, default=None, +parser.add_option("-t", "--timeout", type="float", default=None, help="exit after the specified time") parser.add_option("-I", "--id", help="use the supplied id instead of generating one") parser.add_option("-S", "--subject", help="specify a subject") -- cgit v1.2.1 From b4dcf79489661a2713c702b16ec8e9acc45e7d04 Mon Sep 17 00:00:00 2001 From: Jonathan Robie Date: Wed, 23 Jun 2010 13:44:50 +0000 Subject: Changed README to README.txt throughout the project for consistency. Removed gentools/README.txt, which described Velocity. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@957201 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/README | 319 ---------------------------------------- qpid/python/examples/README.txt | 319 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 319 insertions(+), 319 deletions(-) delete mode 100644 qpid/python/examples/README create mode 100644 qpid/python/examples/README.txt (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/README b/qpid/python/examples/README deleted file mode 100644 index bd30b2a6f4..0000000000 --- a/qpid/python/examples/README +++ /dev/null @@ -1,319 +0,0 @@ -Running the Python Examples -============================ - - -Running the Direct Examples ----------------------------- - -To run the direct examples, do the following: - -1. Make sure that a qpidd broker is running: - - $ ps -eaf | grep qpidd - - If a broker is running, you should see the qpidd process in the output of the above command. - -2.Declare a message queue and bind it to an exchange by running declare_queues.py, as follows: - - $ python declare_queues.py - - This program has no output. After this program has been run, all messages sent to the amq.direct exchange using the routing key routing_key are sent to the queue named message_queue. - -3.Publish a series of messages to the amq.direct exchange by running direct_producer.py, as follows: - - $ python direct_producer.py - -This program has no output; the messages are routed to the message queue, as instructed by the binding. - -4. Read the messages from the message queue using direct_consumer.py or listener.py, as follows: - - $ python direct_consumer.py - - or - - $ python listener.py - -You should see the following output: - -message 0 -message 1 -message 2 -message 3 -message 4 -message 5 -message 6 -message 7 -message 8 -message 9 -That's all, folks! - - - -Running the Fanout Examples ----------------------------- - -To run the programs for the Fanout example, do the following: - -1. Make sure that a qpidd broker is running: - - $ ps -eaf | grep qpidd - -If a broker is running, you should see the qpidd process in the output of the above command. - -2. In separate windows, start two or more fanout consumers or fanout listeners as follows: - - $ python fanout_consumer.py - - or - - $ python listener.py - -These programs each create a private queue, bind it to the amq.fanout exchange, and wait for messages to arrive on their queue. - -3. In a separate window, publish a series of messages to the amq.fanout exchange by running fanout_producer.py, as follows: - - $ python fanout_producer.py - -This program has no output; the messages are routed to the message queue, as instructed by the binding. - -4. Go to the windows where you are running consumers or listeners. You should see the following output for each listener or consumer: - - message 0 - message 1 - message 2 - message 3 - message 4 - message 5 - message 6 - message 7 - message 8 - message 9 - That's all, folks! - - - -Running the Publish-Subscribe Examples ---------------------------------------- - -To run the programs for the Publish-Subscribe example, do the following: - -1. Make sure that a qpidd broker is running: - - $ ps -eaf | grep qpidd - -If a broker is running, you should see the qpidd process in the output of the above command. - -2. In separate windows, start one or more topic subscribers by running topic_subscriber.py, as follows: - - $ python topic_subscriber.py - -You will see output similar to this: - - Queues created - please start the topic producer - Subscribing local queue 'local_news' to news-53408183-fcee-4b92-950b-90abb297e739' - Subscribing local queue 'local_weather' to weather-53408183-fcee-4b92-950b-90abb297e739' - Subscribing local queue 'local_usa' to usa-53408183-fcee-4b92-950b-90abb297e739' - Subscribing local queue 'local_europe' to europe-53408183-fcee-4b92-950b-90abb297e739' - Messages on 'news' queue: - -Each topic consumer creates a set of private queues, and binds each queue to the amq.topic exchange together with a binding that indicates which messages should be routed to the queue. - -3.In another window, start the topic publisher, which publishes messages to the amq.topic exchange, as follows: - - $ python topic_publisher.py - -This program has no output; the messages are routed to the message queues for each topic_consumer as specified by the bindings the consumer created. - -4. Go back to the window for each topic consumer. You should see output like this: - - Messages on 'news' queue: - usa.news 0 - usa.news 1 - usa.news 2 - usa.news 3 - usa.news 4 - europe.news 0 - europe.news 1 - europe.news 2 - europe.news 3 - europe.news 4 - That's all, folks! - Messages on 'weather' queue: - usa.weather 0 - usa.weather 1 - usa.weather 2 - usa.weather 3 - usa.weather 4 - europe.weather 0 - europe.weather 1 - europe.weather 2 - europe.weather 3 - europe.weather 4 - That's all, folks! - Messages on 'usa' queue: - usa.news 0 - usa.news 1 - usa.news 2 - usa.news 3 - usa.news 4 - usa.weather 0 - usa.weather 1 - usa.weather 2 - usa.weather 3 - usa.weather 4 - That's all, folks! - Messages on 'europe' queue: - europe.news 0 - europe.news 1 - europe.news 2 - europe.news 3 - europe.news 4 - europe.weather 0 - europe.weather 1 - europe.weather 2 - europe.weather 3 - europe.weather 4 - That's all, folks! - - -Running the Request/Response Examples --------------------------------------- - -To run the programs for the Request/Response example, do the following: - -1. Make sure that a qpidd broker is running: - - $ ps -eaf | grep qpidd - -If a broker is running, you should see the qpidd process in the output of the above command. - -2. Run the server. - - $ python server.py - -You should see the following output: - - Request server running - run your client now. - (Times out after 100 seconds ...) - -3. In a separate window, start a client: - - $ python client.py - -You should see the following output: - - Request: Twas brillig, and the slithy toves - Request: Did gyre and gimble in the wabe. - Request: All mimsy were the borogroves, - Request: And the mome raths outgrabe. - Messages on queue: reply_to:db0f862e-6b36-4e0f-a4b2-ad049eb435ce - Response: TWAS BRILLIG, AND THE SLITHY TOVES - Response: DID GYRE AND GIMBLE IN THE WABE. - Response: ALL MIMSY WERE THE BOROGROVES, - Response: AND THE MOME RATHS OUTGRABE. - No more messages! - - -Running the XML-based Routing Examples ---------------------------------------- - -To run the programs for the XML-based Routing example, do the following: - -1. Make sure that a qpidd broker is running: - - $ ps -eaf | grep qpidd - -If a broker is running, you should see the qpidd process in the output of the above command. - -2. Declare an XML exchange and a message queue, then bind the queue to the exchange by running declare_queues.py, as follows: - - $ python declare_queues.py - -This program has no output. After this program has been run, all messages sent to the xml exchange using the routing key weather are sent to the queue named message_queue if they satisfy the conditions specified in the following XQuery, which is used in the binding: - - let $w := ./weather - return $w/station = 'Raleigh-Durham International Airport (KRDU)' - and $w/temperature_f > 50 - and $w/temperature_f - $w/dewpoint > 5 - and $w/wind_speed_mph > 7 - and $w/wind_speed_mph < 20 - -3. Publish a series of messages to the xml exchange by running xml_producer.py, as follows: - - $ python xml_producer.py - -The messages are routed to the message queue, as prescribed by the binding. Each message represents a weather report, such as this one: - - - Raleigh-Durham International Airport (KRDU) - 16 - 70 - 35 - - -4. Read the messages from the message queue using direct_consumer.py or listener.py, as follows: - - $ python xml_consumer.py - - or - - $ python listener.py - -You should see the following output: - -Raleigh-Durham International Airport (KRDU) -1670 -35 - - -Running the Headers Examples ------------------------------ - -To run the headers examples, do the following: - -1. Make sure that a qpidd broker is running: - - $ ps -eaf | grep qpidd - - If a broker is running, you should see the qpidd process in the output of the above command. - -2.Declare a message queues and bind them to an exchange by running declare_queues.py, as follows: - - $ python declare_queues.py - - This program has no output. After this program has been run, all messages sent to the amq.match exchange with an application-header of {'class': 'first'} will be routed to the queue named "first" and messages with an application-header of {'class': 'second'} will be routed to the queue named "second". - -3.Publish a series of messages to the amq.match exchange by running headers_producer.py, as follows: - - $ python headers_producer.py - -This program has no output; the messages are routed to the message queues, as instructed by the bindings. - -4. Read the messages from the message queues using headers_consumer.py as follows: - - $ python headers_consumer.py - -You should see the following output: - -message(first) 0 -message(first) 1 -message(first) 2 -message(first) 3 -message(first) 4 -message(first) 5 -message(first) 6 -message(first) 7 -message(first) 8 -message(first) 9 -That's all, folks! -message(second) 0 -message(second) 1 -message(second) 2 -message(second) 3 -message(second) 4 -message(second) 5 -message(second) 6 -message(second) 7 -message(second) 8 -message(second) 9 -That's all, folks! diff --git a/qpid/python/examples/README.txt b/qpid/python/examples/README.txt new file mode 100644 index 0000000000..bd30b2a6f4 --- /dev/null +++ b/qpid/python/examples/README.txt @@ -0,0 +1,319 @@ +Running the Python Examples +============================ + + +Running the Direct Examples +---------------------------- + +To run the direct examples, do the following: + +1. Make sure that a qpidd broker is running: + + $ ps -eaf | grep qpidd + + If a broker is running, you should see the qpidd process in the output of the above command. + +2.Declare a message queue and bind it to an exchange by running declare_queues.py, as follows: + + $ python declare_queues.py + + This program has no output. After this program has been run, all messages sent to the amq.direct exchange using the routing key routing_key are sent to the queue named message_queue. + +3.Publish a series of messages to the amq.direct exchange by running direct_producer.py, as follows: + + $ python direct_producer.py + +This program has no output; the messages are routed to the message queue, as instructed by the binding. + +4. Read the messages from the message queue using direct_consumer.py or listener.py, as follows: + + $ python direct_consumer.py + + or + + $ python listener.py + +You should see the following output: + +message 0 +message 1 +message 2 +message 3 +message 4 +message 5 +message 6 +message 7 +message 8 +message 9 +That's all, folks! + + + +Running the Fanout Examples +---------------------------- + +To run the programs for the Fanout example, do the following: + +1. Make sure that a qpidd broker is running: + + $ ps -eaf | grep qpidd + +If a broker is running, you should see the qpidd process in the output of the above command. + +2. In separate windows, start two or more fanout consumers or fanout listeners as follows: + + $ python fanout_consumer.py + + or + + $ python listener.py + +These programs each create a private queue, bind it to the amq.fanout exchange, and wait for messages to arrive on their queue. + +3. In a separate window, publish a series of messages to the amq.fanout exchange by running fanout_producer.py, as follows: + + $ python fanout_producer.py + +This program has no output; the messages are routed to the message queue, as instructed by the binding. + +4. Go to the windows where you are running consumers or listeners. You should see the following output for each listener or consumer: + + message 0 + message 1 + message 2 + message 3 + message 4 + message 5 + message 6 + message 7 + message 8 + message 9 + That's all, folks! + + + +Running the Publish-Subscribe Examples +--------------------------------------- + +To run the programs for the Publish-Subscribe example, do the following: + +1. Make sure that a qpidd broker is running: + + $ ps -eaf | grep qpidd + +If a broker is running, you should see the qpidd process in the output of the above command. + +2. In separate windows, start one or more topic subscribers by running topic_subscriber.py, as follows: + + $ python topic_subscriber.py + +You will see output similar to this: + + Queues created - please start the topic producer + Subscribing local queue 'local_news' to news-53408183-fcee-4b92-950b-90abb297e739' + Subscribing local queue 'local_weather' to weather-53408183-fcee-4b92-950b-90abb297e739' + Subscribing local queue 'local_usa' to usa-53408183-fcee-4b92-950b-90abb297e739' + Subscribing local queue 'local_europe' to europe-53408183-fcee-4b92-950b-90abb297e739' + Messages on 'news' queue: + +Each topic consumer creates a set of private queues, and binds each queue to the amq.topic exchange together with a binding that indicates which messages should be routed to the queue. + +3.In another window, start the topic publisher, which publishes messages to the amq.topic exchange, as follows: + + $ python topic_publisher.py + +This program has no output; the messages are routed to the message queues for each topic_consumer as specified by the bindings the consumer created. + +4. Go back to the window for each topic consumer. You should see output like this: + + Messages on 'news' queue: + usa.news 0 + usa.news 1 + usa.news 2 + usa.news 3 + usa.news 4 + europe.news 0 + europe.news 1 + europe.news 2 + europe.news 3 + europe.news 4 + That's all, folks! + Messages on 'weather' queue: + usa.weather 0 + usa.weather 1 + usa.weather 2 + usa.weather 3 + usa.weather 4 + europe.weather 0 + europe.weather 1 + europe.weather 2 + europe.weather 3 + europe.weather 4 + That's all, folks! + Messages on 'usa' queue: + usa.news 0 + usa.news 1 + usa.news 2 + usa.news 3 + usa.news 4 + usa.weather 0 + usa.weather 1 + usa.weather 2 + usa.weather 3 + usa.weather 4 + That's all, folks! + Messages on 'europe' queue: + europe.news 0 + europe.news 1 + europe.news 2 + europe.news 3 + europe.news 4 + europe.weather 0 + europe.weather 1 + europe.weather 2 + europe.weather 3 + europe.weather 4 + That's all, folks! + + +Running the Request/Response Examples +-------------------------------------- + +To run the programs for the Request/Response example, do the following: + +1. Make sure that a qpidd broker is running: + + $ ps -eaf | grep qpidd + +If a broker is running, you should see the qpidd process in the output of the above command. + +2. Run the server. + + $ python server.py + +You should see the following output: + + Request server running - run your client now. + (Times out after 100 seconds ...) + +3. In a separate window, start a client: + + $ python client.py + +You should see the following output: + + Request: Twas brillig, and the slithy toves + Request: Did gyre and gimble in the wabe. + Request: All mimsy were the borogroves, + Request: And the mome raths outgrabe. + Messages on queue: reply_to:db0f862e-6b36-4e0f-a4b2-ad049eb435ce + Response: TWAS BRILLIG, AND THE SLITHY TOVES + Response: DID GYRE AND GIMBLE IN THE WABE. + Response: ALL MIMSY WERE THE BOROGROVES, + Response: AND THE MOME RATHS OUTGRABE. + No more messages! + + +Running the XML-based Routing Examples +--------------------------------------- + +To run the programs for the XML-based Routing example, do the following: + +1. Make sure that a qpidd broker is running: + + $ ps -eaf | grep qpidd + +If a broker is running, you should see the qpidd process in the output of the above command. + +2. Declare an XML exchange and a message queue, then bind the queue to the exchange by running declare_queues.py, as follows: + + $ python declare_queues.py + +This program has no output. After this program has been run, all messages sent to the xml exchange using the routing key weather are sent to the queue named message_queue if they satisfy the conditions specified in the following XQuery, which is used in the binding: + + let $w := ./weather + return $w/station = 'Raleigh-Durham International Airport (KRDU)' + and $w/temperature_f > 50 + and $w/temperature_f - $w/dewpoint > 5 + and $w/wind_speed_mph > 7 + and $w/wind_speed_mph < 20 + +3. Publish a series of messages to the xml exchange by running xml_producer.py, as follows: + + $ python xml_producer.py + +The messages are routed to the message queue, as prescribed by the binding. Each message represents a weather report, such as this one: + + + Raleigh-Durham International Airport (KRDU) + 16 + 70 + 35 + + +4. Read the messages from the message queue using direct_consumer.py or listener.py, as follows: + + $ python xml_consumer.py + + or + + $ python listener.py + +You should see the following output: + +Raleigh-Durham International Airport (KRDU) +1670 +35 + + +Running the Headers Examples +----------------------------- + +To run the headers examples, do the following: + +1. Make sure that a qpidd broker is running: + + $ ps -eaf | grep qpidd + + If a broker is running, you should see the qpidd process in the output of the above command. + +2.Declare a message queues and bind them to an exchange by running declare_queues.py, as follows: + + $ python declare_queues.py + + This program has no output. After this program has been run, all messages sent to the amq.match exchange with an application-header of {'class': 'first'} will be routed to the queue named "first" and messages with an application-header of {'class': 'second'} will be routed to the queue named "second". + +3.Publish a series of messages to the amq.match exchange by running headers_producer.py, as follows: + + $ python headers_producer.py + +This program has no output; the messages are routed to the message queues, as instructed by the bindings. + +4. Read the messages from the message queues using headers_consumer.py as follows: + + $ python headers_consumer.py + +You should see the following output: + +message(first) 0 +message(first) 1 +message(first) 2 +message(first) 3 +message(first) 4 +message(first) 5 +message(first) 6 +message(first) 7 +message(first) 8 +message(first) 9 +That's all, folks! +message(second) 0 +message(second) 1 +message(second) 2 +message(second) 3 +message(second) 4 +message(second) 5 +message(second) 6 +message(second) 7 +message(second) 8 +message(second) 9 +That's all, folks! -- cgit v1.2.1 From 2c7e79a2bac98657a2e613ef848e8615939bfc46 Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Tue, 13 Jul 2010 16:33:24 +0000 Subject: removed old python examples git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@963786 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/README.txt | 335 ++------------------- qpid/python/examples/datatypes/client.py | 122 -------- qpid/python/examples/datatypes/server.py | 124 -------- qpid/python/examples/datatypes/testdata.py | 201 ------------- qpid/python/examples/direct/declare_queues.py | 76 ----- qpid/python/examples/direct/direct_consumer.py | 94 ------ qpid/python/examples/direct/direct_producer.py | 73 ----- qpid/python/examples/direct/listener.py | 109 ------- qpid/python/examples/direct/verify | 22 -- qpid/python/examples/direct/verify.in | 14 - qpid/python/examples/fanout/fanout_consumer.py | 99 ------ qpid/python/examples/fanout/fanout_producer.py | 72 ----- qpid/python/examples/fanout/listener.py | 117 ------- qpid/python/examples/fanout/verify | 24 -- qpid/python/examples/fanout/verify.in | 27 -- qpid/python/examples/headers/declare_queues.py | 77 ----- qpid/python/examples/headers/headers_consumer.py | 107 ------- qpid/python/examples/headers/headers_producer.py | 79 ----- qpid/python/examples/headers/verify | 22 -- qpid/python/examples/headers/verify.in | 25 -- qpid/python/examples/pubsub/topic_publisher.py | 92 ------ qpid/python/examples/pubsub/topic_subscriber.py | 154 ---------- qpid/python/examples/pubsub/verify | 23 -- qpid/python/examples/pubsub/verify.in | 55 ---- qpid/python/examples/request-response/client.py | 131 -------- qpid/python/examples/request-response/server.py | 110 ------- qpid/python/examples/request-response/verify | 24 -- qpid/python/examples/request-response/verify.in | 14 - .../python/examples/xml-exchange/declare_queues.py | 90 ------ qpid/python/examples/xml-exchange/listener.py | 105 ------- qpid/python/examples/xml-exchange/verify | 22 -- qpid/python/examples/xml-exchange/verify.in | 15 - qpid/python/examples/xml-exchange/xml_consumer.py | 96 ------ qpid/python/examples/xml-exchange/xml_producer.py | 92 ------ 34 files changed, 29 insertions(+), 2813 deletions(-) delete mode 100755 qpid/python/examples/datatypes/client.py delete mode 100755 qpid/python/examples/datatypes/server.py delete mode 100644 qpid/python/examples/datatypes/testdata.py delete mode 100755 qpid/python/examples/direct/declare_queues.py delete mode 100755 qpid/python/examples/direct/direct_consumer.py delete mode 100755 qpid/python/examples/direct/direct_producer.py delete mode 100755 qpid/python/examples/direct/listener.py delete mode 100644 qpid/python/examples/direct/verify delete mode 100644 qpid/python/examples/direct/verify.in delete mode 100755 qpid/python/examples/fanout/fanout_consumer.py delete mode 100755 qpid/python/examples/fanout/fanout_producer.py delete mode 100755 qpid/python/examples/fanout/listener.py delete mode 100644 qpid/python/examples/fanout/verify delete mode 100644 qpid/python/examples/fanout/verify.in delete mode 100755 qpid/python/examples/headers/declare_queues.py delete mode 100755 qpid/python/examples/headers/headers_consumer.py delete mode 100755 qpid/python/examples/headers/headers_producer.py delete mode 100644 qpid/python/examples/headers/verify delete mode 100644 qpid/python/examples/headers/verify.in delete mode 100755 qpid/python/examples/pubsub/topic_publisher.py delete mode 100755 qpid/python/examples/pubsub/topic_subscriber.py delete mode 100644 qpid/python/examples/pubsub/verify delete mode 100644 qpid/python/examples/pubsub/verify.in delete mode 100755 qpid/python/examples/request-response/client.py delete mode 100755 qpid/python/examples/request-response/server.py delete mode 100644 qpid/python/examples/request-response/verify delete mode 100644 qpid/python/examples/request-response/verify.in delete mode 100755 qpid/python/examples/xml-exchange/declare_queues.py delete mode 100755 qpid/python/examples/xml-exchange/listener.py delete mode 100644 qpid/python/examples/xml-exchange/verify delete mode 100644 qpid/python/examples/xml-exchange/verify.in delete mode 100755 qpid/python/examples/xml-exchange/xml_consumer.py delete mode 100755 qpid/python/examples/xml-exchange/xml_producer.py (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/README.txt b/qpid/python/examples/README.txt index bd30b2a6f4..50bb0a8c9b 100644 --- a/qpid/python/examples/README.txt +++ b/qpid/python/examples/README.txt @@ -1,319 +1,42 @@ -Running the Python Examples -============================ +The Python Examples +=================== +README.txt -- This file. -Running the Direct Examples ----------------------------- +api -- Directory containing drain, spout, + sever, hello, and hello_xml examples. -To run the direct examples, do the following: +api/drain -- A simple messaging client that prints + messages from the source specified on + the command line. -1. Make sure that a qpidd broker is running: +api/spout -- A simple messaging client that sends + messages to the target specified on the + command line. - $ ps -eaf | grep qpidd +api/server -- An example server that process incoming + messages and sends replies. - If a broker is running, you should see the qpidd process in the output of the above command. -2.Declare a message queue and bind it to an exchange by running declare_queues.py, as follows: +api/hello -- An example client that sends a message + and then receives it. - $ python declare_queues.py +api/hello_xml -- An example client that sends a message + to the xml exchange and then receives + it. - This program has no output. After this program has been run, all messages sent to the amq.direct exchange using the routing key routing_key are sent to the queue named message_queue. +reservations -- Directory containing an example machine + reservation system. -3.Publish a series of messages to the amq.direct exchange by running direct_producer.py, as follows: +reservations/common.py -- Utility code used by reserve, + machine-agent, and inventory scripts. - $ python direct_producer.py +reservations/reserve -- Messaging client for listing, reserving, + and releasing machines. -This program has no output; the messages are routed to the message queue, as instructed by the binding. +reservations/machine-agent -- Messaging server that tracks and reports + on the status of its host machine and + listens for reservation requests. -4. Read the messages from the message queue using direct_consumer.py or listener.py, as follows: - - $ python direct_consumer.py - - or - - $ python listener.py - -You should see the following output: - -message 0 -message 1 -message 2 -message 3 -message 4 -message 5 -message 6 -message 7 -message 8 -message 9 -That's all, folks! - - - -Running the Fanout Examples ----------------------------- - -To run the programs for the Fanout example, do the following: - -1. Make sure that a qpidd broker is running: - - $ ps -eaf | grep qpidd - -If a broker is running, you should see the qpidd process in the output of the above command. - -2. In separate windows, start two or more fanout consumers or fanout listeners as follows: - - $ python fanout_consumer.py - - or - - $ python listener.py - -These programs each create a private queue, bind it to the amq.fanout exchange, and wait for messages to arrive on their queue. - -3. In a separate window, publish a series of messages to the amq.fanout exchange by running fanout_producer.py, as follows: - - $ python fanout_producer.py - -This program has no output; the messages are routed to the message queue, as instructed by the binding. - -4. Go to the windows where you are running consumers or listeners. You should see the following output for each listener or consumer: - - message 0 - message 1 - message 2 - message 3 - message 4 - message 5 - message 6 - message 7 - message 8 - message 9 - That's all, folks! - - - -Running the Publish-Subscribe Examples ---------------------------------------- - -To run the programs for the Publish-Subscribe example, do the following: - -1. Make sure that a qpidd broker is running: - - $ ps -eaf | grep qpidd - -If a broker is running, you should see the qpidd process in the output of the above command. - -2. In separate windows, start one or more topic subscribers by running topic_subscriber.py, as follows: - - $ python topic_subscriber.py - -You will see output similar to this: - - Queues created - please start the topic producer - Subscribing local queue 'local_news' to news-53408183-fcee-4b92-950b-90abb297e739' - Subscribing local queue 'local_weather' to weather-53408183-fcee-4b92-950b-90abb297e739' - Subscribing local queue 'local_usa' to usa-53408183-fcee-4b92-950b-90abb297e739' - Subscribing local queue 'local_europe' to europe-53408183-fcee-4b92-950b-90abb297e739' - Messages on 'news' queue: - -Each topic consumer creates a set of private queues, and binds each queue to the amq.topic exchange together with a binding that indicates which messages should be routed to the queue. - -3.In another window, start the topic publisher, which publishes messages to the amq.topic exchange, as follows: - - $ python topic_publisher.py - -This program has no output; the messages are routed to the message queues for each topic_consumer as specified by the bindings the consumer created. - -4. Go back to the window for each topic consumer. You should see output like this: - - Messages on 'news' queue: - usa.news 0 - usa.news 1 - usa.news 2 - usa.news 3 - usa.news 4 - europe.news 0 - europe.news 1 - europe.news 2 - europe.news 3 - europe.news 4 - That's all, folks! - Messages on 'weather' queue: - usa.weather 0 - usa.weather 1 - usa.weather 2 - usa.weather 3 - usa.weather 4 - europe.weather 0 - europe.weather 1 - europe.weather 2 - europe.weather 3 - europe.weather 4 - That's all, folks! - Messages on 'usa' queue: - usa.news 0 - usa.news 1 - usa.news 2 - usa.news 3 - usa.news 4 - usa.weather 0 - usa.weather 1 - usa.weather 2 - usa.weather 3 - usa.weather 4 - That's all, folks! - Messages on 'europe' queue: - europe.news 0 - europe.news 1 - europe.news 2 - europe.news 3 - europe.news 4 - europe.weather 0 - europe.weather 1 - europe.weather 2 - europe.weather 3 - europe.weather 4 - That's all, folks! - - -Running the Request/Response Examples --------------------------------------- - -To run the programs for the Request/Response example, do the following: - -1. Make sure that a qpidd broker is running: - - $ ps -eaf | grep qpidd - -If a broker is running, you should see the qpidd process in the output of the above command. - -2. Run the server. - - $ python server.py - -You should see the following output: - - Request server running - run your client now. - (Times out after 100 seconds ...) - -3. In a separate window, start a client: - - $ python client.py - -You should see the following output: - - Request: Twas brillig, and the slithy toves - Request: Did gyre and gimble in the wabe. - Request: All mimsy were the borogroves, - Request: And the mome raths outgrabe. - Messages on queue: reply_to:db0f862e-6b36-4e0f-a4b2-ad049eb435ce - Response: TWAS BRILLIG, AND THE SLITHY TOVES - Response: DID GYRE AND GIMBLE IN THE WABE. - Response: ALL MIMSY WERE THE BOROGROVES, - Response: AND THE MOME RATHS OUTGRABE. - No more messages! - - -Running the XML-based Routing Examples ---------------------------------------- - -To run the programs for the XML-based Routing example, do the following: - -1. Make sure that a qpidd broker is running: - - $ ps -eaf | grep qpidd - -If a broker is running, you should see the qpidd process in the output of the above command. - -2. Declare an XML exchange and a message queue, then bind the queue to the exchange by running declare_queues.py, as follows: - - $ python declare_queues.py - -This program has no output. After this program has been run, all messages sent to the xml exchange using the routing key weather are sent to the queue named message_queue if they satisfy the conditions specified in the following XQuery, which is used in the binding: - - let $w := ./weather - return $w/station = 'Raleigh-Durham International Airport (KRDU)' - and $w/temperature_f > 50 - and $w/temperature_f - $w/dewpoint > 5 - and $w/wind_speed_mph > 7 - and $w/wind_speed_mph < 20 - -3. Publish a series of messages to the xml exchange by running xml_producer.py, as follows: - - $ python xml_producer.py - -The messages are routed to the message queue, as prescribed by the binding. Each message represents a weather report, such as this one: - - - Raleigh-Durham International Airport (KRDU) - 16 - 70 - 35 - - -4. Read the messages from the message queue using direct_consumer.py or listener.py, as follows: - - $ python xml_consumer.py - - or - - $ python listener.py - -You should see the following output: - -Raleigh-Durham International Airport (KRDU) -1670 -35 - - -Running the Headers Examples ------------------------------ - -To run the headers examples, do the following: - -1. Make sure that a qpidd broker is running: - - $ ps -eaf | grep qpidd - - If a broker is running, you should see the qpidd process in the output of the above command. - -2.Declare a message queues and bind them to an exchange by running declare_queues.py, as follows: - - $ python declare_queues.py - - This program has no output. After this program has been run, all messages sent to the amq.match exchange with an application-header of {'class': 'first'} will be routed to the queue named "first" and messages with an application-header of {'class': 'second'} will be routed to the queue named "second". - -3.Publish a series of messages to the amq.match exchange by running headers_producer.py, as follows: - - $ python headers_producer.py - -This program has no output; the messages are routed to the message queues, as instructed by the bindings. - -4. Read the messages from the message queues using headers_consumer.py as follows: - - $ python headers_consumer.py - -You should see the following output: - -message(first) 0 -message(first) 1 -message(first) 2 -message(first) 3 -message(first) 4 -message(first) 5 -message(first) 6 -message(first) 7 -message(first) 8 -message(first) 9 -That's all, folks! -message(second) 0 -message(second) 1 -message(second) 2 -message(second) 3 -message(second) 4 -message(second) 5 -message(second) 6 -message(second) 7 -message(second) 8 -message(second) 9 -That's all, folks! +reservations/inventory -- Messaging server that tracks the last + known status of machines. diff --git a/qpid/python/examples/datatypes/client.py b/qpid/python/examples/datatypes/client.py deleted file mode 100755 index 088e529909..0000000000 --- a/qpid/python/examples/datatypes/client.py +++ /dev/null @@ -1,122 +0,0 @@ -#!/usr/bin/env python -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -""" - client.py - - Client for testing use of Unicode and datatypes. - - Both client and server will be written in C++ and Python. - Tests can run clients and servers written in different - languages, and they can be run on 32-bit and 64-bit architectures. - -""" - -import qpid -import sys -import os -from qpid.util import connect -from qpid.connection import Connection -from qpid.datatypes import Message, RangedSet, uuid4 -from qpid.queue import Empty - -import testdata - -#----- Initialization -------------------------------------- - - -# Set parameters for login - -host="127.0.0.1" -port=5672 -user="guest" -password="guest" - -# If an alternate host or port has been specified, use that instead -# (this is used in our unit tests) -if len(sys.argv) > 1 : - host=sys.argv[1] -if len(sys.argv) > 2 : - port=int(sys.argv[2]) - -# Create a connection. -socket = connect(host, port) -connection = Connection (sock=socket, username=user, password=password) -connection.start() -session = connection.session(str(uuid4())) - - -#----- Main Body -- ---------------------------------------- - -# Create a response queue for the server to send responses to. Use the -# same string as the name of the queue and the name of the routing -# key. - -reply_to = "reply_to:" + session.name -session.queue_declare(queue=reply_to, exclusive=True) -session.exchange_bind(exchange="amq.direct", queue=reply_to, binding_key=reply_to) - -# Create a local queue and subscribe it to the response queue - -local_queue_name = "local_queue" -queue = session.incoming(local_queue_name) - -# Call message_subscribe() to tell the broker to deliver messages from -# the server's reply_to queue to our local client queue. The server -# will start delivering messages as soon as message credit is -# available. - -session.message_subscribe(queue=reply_to, destination=local_queue_name) -queue.start() - -# Set up the properties. Perhaps a few application headers? - -delivery_properties = session.delivery_properties(routing_key="request") - -message_properties = session.message_properties() - -message_properties.content_encoding="text/plain; charset='utf-8'" - -testdata.set_application_headers(message_properties) -message_properties.reply_to = session.reply_to("amq.direct", reply_to) - -# deliver the message - remember to encode the Unicode string! -request = Message(message_properties, delivery_properties, testdata.String_Greek.encode("utf8")) -session.message_transfer(destination="amq.direct", message=request) - -# Now see what messages the server sent to our reply_to queue - -try: - response = queue.get(timeout=10) - content = response.body - session.message_accept(RangedSet(response.id)) - testdata.check_message(response) - print "Response: " + content -except Empty: - print "No more messages!" - exit(1) -except: - print "Unexpected exception!" - exit(1) - -#----- Cleanup ------------------------------------------------ - -# Clean up before exiting so there are no open threads. - -session.close(timeout=10) diff --git a/qpid/python/examples/datatypes/server.py b/qpid/python/examples/datatypes/server.py deleted file mode 100755 index 18e6fa4ad7..0000000000 --- a/qpid/python/examples/datatypes/server.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -""" - server.py - - Server for testing use of Unicode and datatypes. - - Both client and server will be written in C++ and Python. - Tests can run clients and servers written in different - languages, and they can be run on 32-bit and 64-bit architectures. -""" - -import testdata - -import qpid -import sys -import os -from qpid.util import connect -from qpid.connection import Connection -from qpid.datatypes import Message, RangedSet, uuid4 -from qpid.queue import Empty - -#----- Functions ------------------------------------------- -def respond(session, request): - - # The routing key for the response is the request's reply-to - # property. The body for the response is the request's body, - # converted to upper case. - - testdata.check_message(request) - - message_properties = request.get("message_properties") - reply_to = message_properties.reply_to - - testdata.set_application_headers(message_properties) - - if reply_to == None: - raise Exception("This message is missing the 'reply_to' property, which is required") - - delivery_properties = session.delivery_properties(routing_key=reply_to["routing_key"]) - response = Message(delivery_properties, message_properties, testdata.String_Greek.encode("utf8")) - print "Sending response ..." - session.message_transfer(destination=reply_to["exchange"], message=response) - -#----- Initialization -------------------------------------- - - -# Set parameters for login - -host="127.0.0.1" -port=5672 -user="guest" -password="guest" - -# If an alternate host or port has been specified, use that instead -# (this is used in our unit tests) -if len(sys.argv) > 1 : - host=sys.argv[1] -if len(sys.argv) > 2 : - port=int(sys.argv[2]) - -socket = connect(host, port) -connection = Connection (sock=socket, username=user, password=password) -connection.start() -session = connection.session(str(uuid4())) - -#----- Main Body -- ---------------------------------------- - -# Create a request queue and subscribe to it - -session.queue_declare(queue="request", exclusive=True) -session.exchange_bind(exchange="amq.direct", queue="request", binding_key="request") - -local_queue_name = "local_queue" - -session.message_subscribe(queue="request", destination=local_queue_name) - -queue = session.incoming(local_queue_name) -queue.start() - -# Remind the user to start the client program - -print "Request server running - run your client now." -print "(Times out after 100 seconds ...)" -sys.stdout.flush() - -# Respond to each request - -# If we get a message, send it back to the user (as indicated in the -# ReplyTo property) - -while True: - try: - request = queue.get(timeout=100) - session.message_accept(RangedSet(request.id)) - - respond(session, request) - except Empty: - print "No more messages!" - break; - - -#----- Cleanup ------------------------------------------------ - -# Clean up before exiting so there are no open threads. - -session.close(timeout=10) diff --git a/qpid/python/examples/datatypes/testdata.py b/qpid/python/examples/datatypes/testdata.py deleted file mode 100644 index 251872ff52..0000000000 --- a/qpid/python/examples/datatypes/testdata.py +++ /dev/null @@ -1,201 +0,0 @@ -# -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -# - -# -*- encoding: utf-8 -*- - -from qpid.datatypes import uuid4, timestamp - -#----- Some variables to test boundary conditions on various data types - -void = None -boolean_true = True -boolean_false = False -Uint8_0 = 0 -Uint8_max = 255 -Uint16_0 = 0 -Uint16_max = 65535 -Uint32_0 = 0 -Uint32_max = 4294967295 -Uint64_0 = 0 -Uint64_max = 18446744073709551615 -Int8_min = -128 -Int8_0 = 0 -Int8_max = 127 -Int16_min = -32768 -Int16_0 = 0 -Int16_max = 32767 -Int32_min = -2147483648 -Int32_0 = 0 -Int32_max = 2147483647 -Int64_min = -9223372036854775808 -Int64_0 = 0 -Int64_max = 9223372036854775807 - -Float_pi = 3.14159265 -Float_neg = -1E4 -Float_big = 1267.43233E12 -Float_small = 12.78e-12 -Float_neg0 = -0 -Float_pos0 = 0 -Float_INF = float('inf') -Float_Negative_INF = float('-inf') - -Double_pi = 3.1415926535897932384626433832795 -Double_neg = -1E4 -Double_big = 1267.43233E12 -Double_small = 12.78e-2 -Double_neg0 = -0 -Double_pos0 = 0 -Double_INF = float('inf') -Double_Negative_INF = float('-inf') - -char_1byte = u'0024' # $ -char_2byte = u'00A2' # ¢ -char_3byte = u'20AC' # € -char_4byte = u'10ABCD' - -timestamp = timestamp() - -UUID = uuid4() - -String_Greek = u"ἐξίσταντο δὲ πάντες καὶ διηπόρουν, ἄλλος πρὸς ἄλλον λέγοντες, Τί θέλει τοῦτο εἶναι;" - -String_Empty = "" - -#----- A few functions ---------------------------------------------------------- - -def near_enough(float1, float2, delta): - return abs(float1-float2) < delta - -def set_application_headers(message_properties): - - message_properties.application_headers = {} - message_properties.application_headers["void"] = None - message_properties.application_headers["boolean_true"] = boolean_true - message_properties.application_headers["boolean_false"] = boolean_false - message_properties.application_headers["Uint8_0"] = Uint8_0 - message_properties.application_headers["Uint8_max"] = Uint8_max - message_properties.application_headers["Uint16_0"] = Uint16_0 - message_properties.application_headers["Uint16_max"] = Uint16_max - message_properties.application_headers["Uint32_0"] = Uint32_0 - message_properties.application_headers["Uint32_max"] = Uint32_max - message_properties.application_headers["Uint64_0"] = Uint64_0 -# message_properties.application_headers["Uint64_max"] = Uint64_max - message_properties.application_headers["Int8_min"] = Int8_min - message_properties.application_headers["Int8_0"] = Int8_0 - message_properties.application_headers["Int8_max"] = Int8_max - message_properties.application_headers["Int16_min"] = Int16_min - message_properties.application_headers["Int16_0"] = Int16_0 - message_properties.application_headers["Int16_max"] = Int16_max - message_properties.application_headers["Int32_min"] = Int32_min - message_properties.application_headers["Int32_0"] = Int32_0 - message_properties.application_headers["Int32_max"] = Int32_max - message_properties.application_headers["Int64_min"] = Int64_min - message_properties.application_headers["Int64_0"] = Int64_0 - message_properties.application_headers["Int64_max"] = Int64_max - - message_properties.application_headers["Float_pi"] = Float_pi - message_properties.application_headers["Float_neg"] = Float_neg - message_properties.application_headers["Float_big"] = Float_big - message_properties.application_headers["Float_small"] = Float_small - message_properties.application_headers["Float_neg0"] = Float_neg0 - message_properties.application_headers["Float_pos0"] = Float_pos0 - message_properties.application_headers["Float_INF"] = Float_INF - message_properties.application_headers["Float_Negative_INF"] = Float_Negative_INF - - message_properties.application_headers["Double_pi"] = Double_pi - message_properties.application_headers["Double_neg"] = Double_neg - message_properties.application_headers["Double_big"] = Double_big - message_properties.application_headers["Double_small"] = Double_small - message_properties.application_headers["Double_neg0"] = Double_neg0 - message_properties.application_headers["Double_pos0"] = Double_pos0 - message_properties.application_headers["Double_INF"] = Double_INF - message_properties.application_headers["Double_Negative_INF"] = Double_Negative_INF - - message_properties.application_headers["char_1byte"] = char_1byte - message_properties.application_headers["char_2byte"] = char_2byte - message_properties.application_headers["char_3byte"] = char_3byte - message_properties.application_headers["char_4byte"] = char_4byte - - message_properties.application_headers["timestamp"] = timestamp - message_properties.application_headers["UUID"] = uuid4() - message_properties.application_headers["String_Greek"] = String_Greek - message_properties.application_headers["String_Empty"] = String_Empty - -def check_message(message): - -# message_properties = message.message_properties() - message_properties = message.get("message_properties") - assert message_properties.application_headers["void"] == None - assert message_properties.application_headers["boolean_true"] == boolean_true - assert message_properties.application_headers["boolean_false"] == boolean_false - assert message_properties.application_headers["Uint8_0"] == Uint8_0 - assert message_properties.application_headers["Uint8_max"] == Uint8_max - assert message_properties.application_headers["Uint16_0"] == Uint16_0 - assert message_properties.application_headers["Uint16_max"] == Uint16_max - assert message_properties.application_headers["Uint32_0"] == Uint32_0 - assert message_properties.application_headers["Uint32_max"] == Uint32_max - assert message_properties.application_headers["Uint64_0"] == Uint64_0 -# assert message_properties.application_headers["Uint64_max"] == Uint64_max - assert message_properties.application_headers["Int8_min"] == Int8_min - assert message_properties.application_headers["Int8_0"] == Int8_0 - assert message_properties.application_headers["Int8_max"] == Int8_max - assert message_properties.application_headers["Int16_min"] == Int16_min - assert message_properties.application_headers["Int16_0"] == Int16_0 - assert message_properties.application_headers["Int16_max"] == Int16_max - assert message_properties.application_headers["Int32_min"] == Int32_min - assert message_properties.application_headers["Int32_0"] == Int32_0 - assert message_properties.application_headers["Int32_max"] == Int32_max - assert message_properties.application_headers["Int64_min"] == Int64_min - assert message_properties.application_headers["Int64_0"] == Int64_0 - assert message_properties.application_headers["Int64_max"] == Int64_max - -# Change floating point comparisons to allow inexactness - - assert near_enough(message_properties.application_headers["Float_pi"], Float_pi, 0.00001) - assert near_enough(message_properties.application_headers["Float_neg"], Float_neg, 0.00001) - assert near_enough(message_properties.application_headers["Float_big"], Float_big, Float_big/1000000) - assert near_enough(message_properties.application_headers["Float_small"], Float_small, 0.00001) - assert message_properties.application_headers["Float_neg0"] == Float_neg0 - assert message_properties.application_headers["Float_pos0"] == Float_pos0 - assert message_properties.application_headers["Float_INF"] == Float_INF - assert message_properties.application_headers["Float_Negative_INF"] == Float_Negative_INF - - assert near_enough(message_properties.application_headers["Double_pi"], Double_pi, 0.00001) - assert near_enough(message_properties.application_headers["Double_neg"], Double_neg, 0.00001) - assert near_enough(message_properties.application_headers["Double_big"], Double_big, Double_big/1000000) - assert near_enough(message_properties.application_headers["Double_small"], Double_small, 0.00001) - assert message_properties.application_headers["Double_neg0"] == Double_neg0 - assert message_properties.application_headers["Double_pos0"] == Double_pos0 - assert message_properties.application_headers["Double_INF"] == Double_INF - assert message_properties.application_headers["Double_Negative_INF"] == Double_Negative_INF - - assert message_properties.application_headers["char_1byte"] == char_1byte - assert message_properties.application_headers["char_2byte"] == char_2byte - assert message_properties.application_headers["char_3byte"] == char_3byte - assert message_properties.application_headers["char_4byte"] == char_4byte - -# assert message_properties.application_headers["timestamp"] == timestamp -# assert message_properties.application_headers["UUID"] == UUID - assert message_properties.application_headers["String_Greek"] == String_Greek - assert message_properties.application_headers["String_Empty"] == String_Empty - - diff --git a/qpid/python/examples/direct/declare_queues.py b/qpid/python/examples/direct/declare_queues.py deleted file mode 100755 index 13818ee9d7..0000000000 --- a/qpid/python/examples/direct/declare_queues.py +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env python -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -""" - declare_queues.py - - Creates and binds a queue on an AMQP direct exchange. - - All messages using the routing key "routing_key" are - sent to the queue named "message_queue". -""" - -# Common includes - -import qpid -import sys -import os -from qpid.util import connect -from qpid.connection import Connection -from qpid.datatypes import Message, RangedSet, uuid4 -from qpid.queue import Empty - -#----- Initialization ----------------------------------- - -# Set parameters for login - -host="127.0.0.1" -port=5672 -user="guest" -password="guest" - -# If an alternate host or port has been specified, use that instead -# (this is used in our unit tests) -if len(sys.argv) > 1 : - host=sys.argv[1] -if len(sys.argv) > 2 : - port=int(sys.argv[2]) - -# Create a connection. -socket = connect(host, port) -connection = Connection (sock=socket, username=user, password=password) -connection.start() -session = connection.session(str(uuid4())) - -#----- Create a queue ------------------------------------- - -# queue_declare() creates an AMQP queue, which is held -# on the broker. Published messages are sent to the AMQP queue, -# from which messages are delivered to consumers. -# -# exchange_bind() determines which messages are routed to a queue. -# Route all messages with the binding key "routing_key" to -# the AMQP queue named "message_queue". - -session.queue_declare(queue="message_queue") -session.exchange_bind(exchange="amq.direct", queue="message_queue", binding_key="routing_key") - -#----- Cleanup --------------------------------------------- - -session.close(timeout=10) diff --git a/qpid/python/examples/direct/direct_consumer.py b/qpid/python/examples/direct/direct_consumer.py deleted file mode 100755 index b07e53c5c7..0000000000 --- a/qpid/python/examples/direct/direct_consumer.py +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env python -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -""" - direct_consumer.py - - This AMQP client reads messages from a message - queue named "message_queue". -""" - -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, RangedSet, uuid4 -from qpid.queue import Empty - - -#----- Initialization -------------------------------------- - -# Set parameters for login - -host="127.0.0.1" -port=5672 -user="guest" -password="guest" - -# If an alternate host or port has been specified, use that instead -# (this is used in our unit tests) -if len(sys.argv) > 1 : - host=sys.argv[1] -if len(sys.argv) > 2 : - port=int(sys.argv[2]) - -# Create a connection. -socket = connect(host, port) -connection = Connection (sock=socket, username=user, password=password) -connection.start() -session = connection.session(str(uuid4())) - -#----- Read from queue -------------------------------------------- - -# Now let's create a local client queue and tell it to read -# incoming messages. - -# The consumer tag identifies the client-side queue. - -local_queue_name = "local_queue" -queue = session.incoming(local_queue_name) - -# Call message_subscribe() to tell the broker to deliver messages -# from the AMQP queue to this local client queue. The broker will -# start delivering messages as soon as credit is allocated using -# queue.start(). - -session.message_subscribe(queue="message_queue", destination=local_queue_name) -queue.start() - -# Initialize 'final' and 'content', variables used to identify the last message. - -final = "That's all, folks!" # In a message body, signals the last message -content = "" # Content of the last message read - -message = None -while content != final: - message = queue.get(timeout=10) - content = message.body - session.message_accept(RangedSet(message.id)) - print content - -#----- Cleanup ------------------------------------------------ - -# Clean up before exiting so there are no open threads. -# - -session.close(timeout=10) diff --git a/qpid/python/examples/direct/direct_producer.py b/qpid/python/examples/direct/direct_producer.py deleted file mode 100755 index fcbb4675e4..0000000000 --- a/qpid/python/examples/direct/direct_producer.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env python -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -""" - direct_producer.py - - Publishes messages to an AMQP direct exchange, using - the routing key "routing_key" -""" - -import qpid -import sys -import os -from qpid.util import connect -from qpid.connection import Connection -from qpid.datatypes import Message -from qpid.datatypes import uuid4 -from qpid.queue import Empty - - -#----- Initialization ----------------------------------- - -# Set parameters for login - -host="127.0.0.1" -port=5672 -user="guest" -password="guest" - -# If an alternate host or port has been specified, use that instead -# (this is used in our unit tests) -if len(sys.argv) > 1 : - host=sys.argv[1] -if len(sys.argv) > 2 : - port=int(sys.argv[2]) - -# Create a connection. -socket = connect(host, port) -connection = Connection (sock=socket, username=user, password=password) -connection.start() -session = connection.session(str(uuid4())) - -#----- Publish some messages ------------------------------ - -# Create some messages and put them on the broker. -props = session.delivery_properties(routing_key="routing_key") - -for i in range(10): - session.message_transfer(destination="amq.direct", message=Message(props,"message " + str(i))) - -session.message_transfer(destination="amq.direct", message=Message(props,"That's all, folks!")) - -#----- Cleanup -------------------------------------------- - -# Clean up before exiting so there are no open threads. - -session.close(timeout=10) diff --git a/qpid/python/examples/direct/listener.py b/qpid/python/examples/direct/listener.py deleted file mode 100755 index 9d06bd3929..0000000000 --- a/qpid/python/examples/direct/listener.py +++ /dev/null @@ -1,109 +0,0 @@ -#!/usr/bin/env python -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -""" - listener.py - - This AMQP client reads messages from a message - queue named "message_queue". It is implemented - as a message listener. -""" - -# Common includes - -import qpid -import sys -import os -from qpid.util import connect -from qpid.connection import Connection -from qpid.datatypes import Message, RangedSet, uuid4 -from qpid.queue import Empty - -# Includes specific to this example - -from time import sleep - - -#----- Message Receive Handler ----------------------------- -class Receiver: - def __init__ (self): - self.finalReceived = False - - def isFinal (self): - return self.finalReceived - - def Handler (self, message): - content = message.body - session.message_accept(RangedSet(message.id)) - print content - if content == "That's all, folks!": - self.finalReceived = True - -#----- Initialization -------------------------------------- - -# Set parameters for login - -host="127.0.0.1" -port=5672 -user="guest" -password="guest" - -# If an alternate host or port has been specified, use that instead -# (this is used in our unit tests) -if len(sys.argv) > 1 : - host=sys.argv[1] -if len(sys.argv) > 2 : - port=int(sys.argv[2]) - -# Create a connection. -socket = connect(host, port) -connection = Connection (sock=socket, username=user, password=password) -connection.start() -session = connection.session(str(uuid4())) - -#----- Read from queue -------------------------------------------- - -# Now let's create a local client queue and tell it to read -# incoming messages. - -# The local_queue_name identifies the client-side queue. - -local_queue_name = "local_queue" -queue = session.incoming(local_queue_name) - -# Call message_subscribe() to tell the broker to deliver messages -# from the AMQP queue to this local client queue. The broker will -# start delivering messages as soon as message_subscribe() is called. - -session.message_subscribe(queue="message_queue", destination=local_queue_name) -queue.start() - -receiver = Receiver() -queue.listen (receiver.Handler) - -while not receiver.isFinal() : - sleep (1) - - -#----- Cleanup ------------------------------------------------ - -# Clean up before exiting so there are no open threads. -# - -session.close(timeout=10) diff --git a/qpid/python/examples/direct/verify b/qpid/python/examples/direct/verify deleted file mode 100644 index 92f87bf827..0000000000 --- a/qpid/python/examples/direct/verify +++ /dev/null @@ -1,22 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -clients ./declare_queues.py ./direct_producer.py ./direct_consumer.py -outputs ./declare_queues.py.out ./direct_producer.py.out ./direct_consumer.py.out diff --git a/qpid/python/examples/direct/verify.in b/qpid/python/examples/direct/verify.in deleted file mode 100644 index 5e691619d9..0000000000 --- a/qpid/python/examples/direct/verify.in +++ /dev/null @@ -1,14 +0,0 @@ -==== declare_queues.py.out -==== direct_producer.py.out -==== direct_consumer.py.out -message 0 -message 1 -message 2 -message 3 -message 4 -message 5 -message 6 -message 7 -message 8 -message 9 -That's all, folks! diff --git a/qpid/python/examples/fanout/fanout_consumer.py b/qpid/python/examples/fanout/fanout_consumer.py deleted file mode 100755 index 0452baa8da..0000000000 --- a/qpid/python/examples/fanout/fanout_consumer.py +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env python -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -""" - fanout_consumer.py - - This AMQP client reads messages from a message - queue named "message_queue". -""" -import qpid -import sys -import os -from qpid.util import connect -from qpid.connection import Connection -from qpid.datatypes import Message, RangedSet, uuid4 -from qpid.queue import Empty - -#----- Initialization -------------------------------------- - - -# Set parameters for login - -host="127.0.0.1" -port=5672 -user="guest" -password="guest" - -# If an alternate host or port has been specified, use that instead -# (this is used in our unit tests) -if len(sys.argv) > 1 : - host=sys.argv[1] -if len(sys.argv) > 2 : - port=int(sys.argv[2]) - -# Create a connection. -socket = connect(host, port) -connection = Connection (sock=socket, username=user, password=password) -connection.start() -session = connection.session(str(uuid4())) - - -#----- Main Body ------------------------------------------- - -# Create a server-side queue and route messages to it. -# The server-side queue must have a unique name. Use the -# session id for that. -server_queue_name = session.name -session.queue_declare(queue=server_queue_name) -session.exchange_bind(queue=server_queue_name, exchange="amq.fanout") - -# Create a local queue to receive messages from the server-side -# queue. -local_queue_name = "local_queue" -local_queue = session.incoming(local_queue_name) - -# Call message_subscribe() to tell the server to deliver messages -# from the AMQP queue to this local client queue. - -session.message_subscribe(queue=server_queue_name, destination=local_queue_name) -local_queue.start() - -print "Subscribed to queue " + server_queue_name -sys.stdout.flush() - -# Initialize 'final' and 'content', variables used to identify the last message. -final = "That's all, folks!" # In a message body, signals the last message -content = "" # Content of the last message read - -# Read the messages - acknowledge each one -message = None -while content != final: - message = local_queue.get(timeout=10) - content = message.body - session.message_accept(RangedSet(message.id)) - print content - - -#----- Cleanup ------------------------------------------------ - -# Clean up before exiting so there are no open threads. -# - -session.close(timeout=10) diff --git a/qpid/python/examples/fanout/fanout_producer.py b/qpid/python/examples/fanout/fanout_producer.py deleted file mode 100755 index c4df252c70..0000000000 --- a/qpid/python/examples/fanout/fanout_producer.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env python -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -""" - fanout_producer.py - - Publishes messages to an AMQP direct exchange, using - the routing key "routing_key" -""" -import qpid -import sys -import os -from qpid.util import connect -from qpid.connection import Connection -from qpid.datatypes import Message, uuid4 -from qpid.queue import Empty - -#----- Initialization ----------------------------------- - -# Set parameters for login - -host="127.0.0.1" -port=5672 -user="guest" -password="guest" - -# If an alternate host or port has been specified, use that instead -# (this is used in our unit tests) -if len(sys.argv) > 1 : - host=sys.argv[1] -if len(sys.argv) > 2 : - port=int(sys.argv[2]) - -# Create a connection. -socket = connect(host, port) -connection = Connection (sock=socket, username=user, password=password) -connection.start() -session = connection.session(str(uuid4())) - - -#----- Publish some messages ------------------------------ - -# Create some messages and put them on the broker. - -delivery_properties = session.delivery_properties(routing_key="routing_key") - -for i in range(10): - session.message_transfer(destination="amq.fanout", message=Message(delivery_properties,"message " + str(i))) - -session.message_transfer(destination="amq.fanout", message=Message(delivery_properties, "That's all, folks!")) - -#----- Cleanup -------------------------------------------- - -# Clean up before exiting so there are no open threads. - -session.close(timeout=10) diff --git a/qpid/python/examples/fanout/listener.py b/qpid/python/examples/fanout/listener.py deleted file mode 100755 index 29db402e9d..0000000000 --- a/qpid/python/examples/fanout/listener.py +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/env python -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -""" - listener.py - - This AMQP client reads messages from a message - queue named "message_queue". -""" - -import qpid -import sys -import os -from qpid.util import connect -from qpid.connection import Connection -from qpid.datatypes import Message, RangedSet, uuid4 -from qpid.queue import Empty - -# - -from time import sleep - -#----- Message Receive Handler ----------------------------- -class Receiver: - def __init__ (self): - self.finalReceived = False - - def isFinal (self): - return self.finalReceived - - def Handler (self, message): - content = message.body - session.message_accept(RangedSet(message.id)) - print content - if content == "That's all, folks!": - self.finalReceived = True - - -#----- Initialization -------------------------------------- - -# Set parameters for login - -host="127.0.0.1" -port=5672 -user="guest" -password="guest" - -# If an alternate host or port has been specified, use that instead -# (this is used in our unit tests) -if len(sys.argv) > 1 : - host=sys.argv[1] -if len(sys.argv) > 2 : - port=int(sys.argv[2]) - -# Create a connection. -socket = connect(host, port) -connection = Connection (sock=socket, username=user, password=password) -connection.start() -session = connection.session(str(uuid4())) - -#----- Read from queue -------------------------------------------- - -# Create a server-side queue and route messages to it. -# The server-side queue must have a unique name. Use the -# session id for that. - -server_queue_name = session.name -session.queue_declare(queue=server_queue_name) -session.exchange_bind(queue=server_queue_name, exchange="amq.fanout") - -# Create a local queue to receive messages from the server-side -# queue. -local_queue_name = "local_queue" -local_queue = session.incoming(local_queue_name) - - -# The local queue name identifies the client-side queue. - -local_queue_name = "local_queue" -local_queue = session.incoming(local_queue_name) - -# Call message_subscribe() to tell the broker to deliver messages -# from the AMQP queue to this local client queue. The broker will -# start delivering messages as soon as local_queue.start() is called. - -session.message_subscribe(queue=server_queue_name, destination=local_queue_name) -local_queue.start() - -receiver = Receiver () -local_queue.listen (receiver.Handler) - -while not receiver.isFinal (): - sleep (1) - - -#----- Cleanup ------------------------------------------------ - -# Clean up before exiting so there are no open threads. -# - -session.close() diff --git a/qpid/python/examples/fanout/verify b/qpid/python/examples/fanout/verify deleted file mode 100644 index 9e5c364bfa..0000000000 --- a/qpid/python/examples/fanout/verify +++ /dev/null @@ -1,24 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -background "Subscribed" ./fanout_consumer.py -background "Subscribed" ./fanout_consumer.py -clients ./fanout_producer.py -outputs ./fanout_producer.py.out "./fanout_consumer.py.out | remove_uuid" "./fanout_consumer.pyX.out | remove_uuid" diff --git a/qpid/python/examples/fanout/verify.in b/qpid/python/examples/fanout/verify.in deleted file mode 100644 index d4b8670de9..0000000000 --- a/qpid/python/examples/fanout/verify.in +++ /dev/null @@ -1,27 +0,0 @@ -==== fanout_producer.py.out -==== fanout_consumer.py.out | remove_uuid -Subscribed to queue -message 0 -message 1 -message 2 -message 3 -message 4 -message 5 -message 6 -message 7 -message 8 -message 9 -That's all, folks! -==== fanout_consumer.pyX.out | remove_uuid -Subscribed to queue -message 0 -message 1 -message 2 -message 3 -message 4 -message 5 -message 6 -message 7 -message 8 -message 9 -That's all, folks! diff --git a/qpid/python/examples/headers/declare_queues.py b/qpid/python/examples/headers/declare_queues.py deleted file mode 100755 index e976f71e55..0000000000 --- a/qpid/python/examples/headers/declare_queues.py +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env python -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -""" - declare_queues.py - - Creates and binds a queue on an AMQP headers exchange. - - All messages with an application header of {'class': 'first'} are sent to queue "first". - All messages with an application header of {'class': 'second'} are sent to queue "second". -""" - -# Common includes - -import qpid -import sys -import os -from qpid.util import connect -from qpid.connection import Connection -from qpid.datatypes import Message, RangedSet, uuid4 -from qpid.queue import Empty - -#----- Initialization ----------------------------------- - -# Set parameters for login - -host="127.0.0.1" -port=5672 -user="guest" -password="guest" - -# If an alternate host or port has been specified, use that instead -# (this is used in our unit tests) -if len(sys.argv) > 1 : - host=sys.argv[1] -if len(sys.argv) > 2 : - port=int(sys.argv[2]) - -# Create a connection. -socket = connect(host, port) -connection = Connection (sock=socket, username=user, password=password) -connection.start() -session = connection.session(str(uuid4())) - -#----- Create queues ------------------------------------- - -# queue_declare() creates an AMQP queue, which is held -# on the broker. Published messages are sent to the AMQP queue, -# from which messages are delivered to consumers. -# -# exchange_bind() determines which messages are routed to a queue. - -session.queue_declare(queue="first") -session.exchange_bind(exchange="amq.match", queue="first", binding_key="first", arguments={'x-match':'any', 'class':'first'}) - -session.queue_declare(queue="second") -session.exchange_bind(exchange="amq.match", queue="second", binding_key="second", arguments={'x-match':'any', 'class':'second'}) - -#----- Cleanup --------------------------------------------- - -session.close(timeout=10) diff --git a/qpid/python/examples/headers/headers_consumer.py b/qpid/python/examples/headers/headers_consumer.py deleted file mode 100755 index 8f5ce3c5ff..0000000000 --- a/qpid/python/examples/headers/headers_consumer.py +++ /dev/null @@ -1,107 +0,0 @@ -#!/usr/bin/env python -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -""" - headers_consumer.py - - This AMQP client reads messages from two message - queues named "first" and "second". -""" - -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, RangedSet, uuid4 -from qpid.queue import Empty - - -#----- Initialization -------------------------------------- - -# Set parameters for login - -host="127.0.0.1" -port=5672 -user="guest" -password="guest" - -# If an alternate host or port has been specified, use that instead -# (this is used in our unit tests) -if len(sys.argv) > 1 : - host=sys.argv[1] -if len(sys.argv) > 2 : - port=int(sys.argv[2]) - -# Create a connection. -socket = connect(host, port) -connection = Connection (sock=socket, username=user, password=password) -connection.start() -session = connection.session(str(uuid4())) - -#----- Read from queue -------------------------------------------- - -# Now let's create two local client queues and tell them to read -# incoming messages. - -# The consumer tag identifies the client-side queue. - -local_queue_name_first = "local_queue_first" -local_queue_name_second = "local_queue_second" - -queue_first = session.incoming(local_queue_name_first) -queue_second = session.incoming(local_queue_name_second) - -# Call message_subscribe() to tell the broker to deliver messages -# from the AMQP queue to these local client queues. The broker will -# start delivering messages as soon as credit is allocated using -# queue.start(). - -session.message_subscribe(queue="first", destination=local_queue_name_first) -session.message_subscribe(queue="second", destination=local_queue_name_second) - -queue_first.start() -queue_second.start() - -# Initialize 'final' and 'content', variables used to identify the last message. - -final = "That's all, folks!" # In a message body, signals the last message -content = "" # Content of the last message read - -message = None -while content != final: - message = queue_first.get(timeout=10) - content = message.body - session.message_accept(RangedSet(message.id)) - print content - -content = "" -while content != final: - message = queue_second.get(timeout=10) - content = message.body - session.message_accept(RangedSet(message.id)) - print content - -#----- Cleanup ------------------------------------------------ - -# Clean up before exiting so there are no open threads. -# - -session.close(timeout=10) diff --git a/qpid/python/examples/headers/headers_producer.py b/qpid/python/examples/headers/headers_producer.py deleted file mode 100755 index 43130d5993..0000000000 --- a/qpid/python/examples/headers/headers_producer.py +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env python -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -""" - headers_producer.py - - Publishes messages to an AMQP headers exchange, using - various application header values. -""" - -import qpid -import sys -import os -from qpid.util import connect -from qpid.connection import Connection -from qpid.datatypes import Message -from qpid.datatypes import uuid4 -from qpid.queue import Empty - - -#----- Initialization ----------------------------------- - -# Set parameters for login - -host="127.0.0.1" -port=5672 -user="guest" -password="guest" - -# If an alternate host or port has been specified, use that instead -# (this is used in our unit tests) -if len(sys.argv) > 1 : - host=sys.argv[1] -if len(sys.argv) > 2 : - port=int(sys.argv[2]) - -# Create a connection. -socket = connect(host, port) -connection = Connection (sock=socket, username=user, password=password) -connection.start() -session = connection.session(str(uuid4())) - -#----- Publish some messages ------------------------------ - -# Create some messages and put them on the broker. -props_first = session.message_properties(application_headers={'class':'first'}) -props_second = session.message_properties(application_headers={'class':'second'}) -props_third = session.message_properties(application_headers={'class':'third'}) - -for i in range(10): - session.message_transfer(destination="amq.match", message=Message(props_first,"message(first) " + str(i))) - session.message_transfer(destination="amq.match", message=Message(props_second,"message(second) " + str(i))) - session.message_transfer(destination="amq.match", message=Message(props_third,"message(third) " + str(i))) - -session.message_transfer(destination="amq.match", message=Message(props_first,"That's all, folks!")) -session.message_transfer(destination="amq.match", message=Message(props_second,"That's all, folks!")) -session.message_transfer(destination="amq.match", message=Message(props_third,"That's all, folks!")) - -#----- Cleanup -------------------------------------------- - -# Clean up before exiting so there are no open threads. - -session.close(timeout=10) diff --git a/qpid/python/examples/headers/verify b/qpid/python/examples/headers/verify deleted file mode 100644 index 5fe96c5c23..0000000000 --- a/qpid/python/examples/headers/verify +++ /dev/null @@ -1,22 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -clients ./declare_queues.py ./headers_producer.py ./headers_consumer.py -outputs ./declare_queues.py.out ./headers_producer.py.out ./headers_consumer.py.out diff --git a/qpid/python/examples/headers/verify.in b/qpid/python/examples/headers/verify.in deleted file mode 100644 index 90ffd0a071..0000000000 --- a/qpid/python/examples/headers/verify.in +++ /dev/null @@ -1,25 +0,0 @@ -==== declare_queues.py.out -==== headers_producer.py.out -==== headers_consumer.py.out -message(first) 0 -message(first) 1 -message(first) 2 -message(first) 3 -message(first) 4 -message(first) 5 -message(first) 6 -message(first) 7 -message(first) 8 -message(first) 9 -That's all, folks! -message(second) 0 -message(second) 1 -message(second) 2 -message(second) 3 -message(second) 4 -message(second) 5 -message(second) 6 -message(second) 7 -message(second) 8 -message(second) 9 -That's all, folks! diff --git a/qpid/python/examples/pubsub/topic_publisher.py b/qpid/python/examples/pubsub/topic_publisher.py deleted file mode 100755 index b50d5fa8ca..0000000000 --- a/qpid/python/examples/pubsub/topic_publisher.py +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env python -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -""" - 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 -import sys -import os -from qpid.util import connect -from qpid.connection import Connection -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="127.0.0.1" -port=5672 -user="guest" -password="guest" - -# If an alternate host or port has been specified, use that instead -# (this is used in our unit tests) -if len(sys.argv) > 1 : - host=sys.argv[1] -if len(sys.argv) > 2 : - port=int(sys.argv[2]) - -# Create a connection. -socket = connect(host, port) -connection = Connection (sock=socket) -connection.start() -session = connection.session(str(uuid4())) - -#----- 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 -send_msg("usa.news") - -# usa.weather -send_msg("usa.weather") - -# europe.news -send_msg("europe.news") - -# europe.weather -send_msg("europe.weather") - -# Signal termination -props = session.delivery_properties(routing_key="control") -session.message_transfer(destination="amq.topic", message=Message(props,"That's all, folks!")) - - -#----- Cleanup -------------------------------------------- - -# Clean up before exiting so there are no open threads. - -session.close(timeout=10) diff --git a/qpid/python/examples/pubsub/topic_subscriber.py b/qpid/python/examples/pubsub/topic_subscriber.py deleted file mode 100755 index 489c7cbb19..0000000000 --- a/qpid/python/examples/pubsub/topic_subscriber.py +++ /dev/null @@ -1,154 +0,0 @@ -#!/usr/bin/env python -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -""" - topic_subscriber.py - - This subscriber creates private queues and binds them - to the topics 'usa.#', 'europe.#', '#.news', and '#.weather'. -""" - -import qpid -import sys -import os -from qpid.util import connect -from qpid.connection import Connection -from qpid.datatypes import Message, RangedSet, uuid4 -from qpid.queue import Empty - -#----- Functions ------------------------------------------- - -def dump_queue(queue): - - content = "" # Content of the last message read - final = "That's all, folks!" # In a message body, signals the last message - message = 0 - - while content != final: - try: - message = queue.get(timeout=10) - content = message.body - session.message_accept(RangedSet(message.id)) - print content - except Empty: - print "No more messages!" - return - - - -def subscribe_queue(server_queue_name, local_queue_name): - - print "Subscribing local queue '" + local_queue_name + "' to " + server_queue_name + "'" - - queue = session.incoming(local_queue_name) - - session.message_subscribe(queue=server_queue_name, destination=local_queue_name) - queue.start() - - return queue - -#----- Initialization -------------------------------------- - -# Set parameters for login - -host="127.0.0.1" -port=5672 -user="guest" -password="guest" - -# If an alternate host or port has been specified, use that instead -# (this is used in our unit tests) -if len(sys.argv) > 1 : - host=sys.argv[1] -if len(sys.argv) > 2 : - port=int(sys.argv[2]) - -# Create a connection. -socket = connect(host, port) -connection = Connection (sock=socket, username=user, password=password) -connection.start() -session = connection.session(str(uuid4())) - -#----- Main Body -- ---------------------------------------- - -# declare queues on the server - -news = "news-" + session.name -weather = "weather-" + session.name -usa = "usa-" + session.name -europe = "europe-" + session.name - -session.queue_declare(queue=news, exclusive=True) -session.queue_declare(queue=weather, exclusive=True) -session.queue_declare(queue=usa, exclusive=True) -session.queue_declare(queue=europe, exclusive=True) - -# Routing keys may be "usa.news", "usa.weather", "europe.news", or "europe.weather". - -# The '#' symbol matches one component of a multipart name, e.g. "#.news" matches -# "europe.news" or "usa.news". - -session.exchange_bind(exchange="amq.topic", queue=news, binding_key="#.news") -session.exchange_bind(exchange="amq.topic", queue=weather, binding_key="#.weather") -session.exchange_bind(exchange="amq.topic", queue=usa, binding_key="usa.#") -session.exchange_bind(exchange="amq.topic", queue=europe, binding_key="europe.#") - -# Bind each queue to the control queue so we know when to stop - -session.exchange_bind(exchange="amq.topic", queue=news, binding_key="control") -session.exchange_bind(exchange="amq.topic", queue=weather, binding_key="control") -session.exchange_bind(exchange="amq.topic", queue=usa, binding_key="control") -session.exchange_bind(exchange="amq.topic", queue=europe, binding_key="control") - -# Remind the user to start the topic producer - -print "Queues created - please start the topic producer" -sys.stdout.flush() - -# Subscribe local queues to server queues - -local_news = "local_news" -local_weather = "local_weather" -local_usa = "local_usa" -local_europe = "local_europe" - -local_news_queue = subscribe_queue(news, local_news) -local_weather_queue = subscribe_queue(weather, local_weather) -local_usa_queue = subscribe_queue(usa, local_usa) -local_europe_queue = subscribe_queue(europe, local_europe) - -# Call dump_queue to print messages from each queue - -print "Messages on 'news' queue:" -dump_queue(local_news_queue) - -print "Messages on 'weather' queue:" -dump_queue(local_weather_queue) - -print "Messages on 'usa' queue:" -dump_queue(local_usa_queue) - -print "Messages on 'europe' queue:" -dump_queue(local_europe_queue) - -#----- Cleanup ------------------------------------------------ - -# Clean up before exiting so there are no open threads. - -session.close(timeout=10) diff --git a/qpid/python/examples/pubsub/verify b/qpid/python/examples/pubsub/verify deleted file mode 100644 index cf1bade62e..0000000000 --- a/qpid/python/examples/pubsub/verify +++ /dev/null @@ -1,23 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -background "Queues created" ./topic_subscriber.py -clients ./topic_publisher.py -outputs ./topic_publisher.py.out "topic_subscriber.py.out | remove_uuid | sort" diff --git a/qpid/python/examples/pubsub/verify.in b/qpid/python/examples/pubsub/verify.in deleted file mode 100644 index ac1506b324..0000000000 --- a/qpid/python/examples/pubsub/verify.in +++ /dev/null @@ -1,55 +0,0 @@ -==== topic_publisher.py.out -==== topic_subscriber.py.out | remove_uuid | sort -Messages on 'europe' queue: -Messages on 'news' queue: -Messages on 'usa' queue: -Messages on 'weather' queue: -Queues created - please start the topic producer -Subscribing local queue 'local_europe' to europe-' -Subscribing local queue 'local_news' to news-' -Subscribing local queue 'local_usa' to usa-' -Subscribing local queue 'local_weather' to weather-' -That's all, folks! -That's all, folks! -That's all, folks! -That's all, folks! -europe.news 0 -europe.news 0 -europe.news 1 -europe.news 1 -europe.news 2 -europe.news 2 -europe.news 3 -europe.news 3 -europe.news 4 -europe.news 4 -europe.weather 0 -europe.weather 0 -europe.weather 1 -europe.weather 1 -europe.weather 2 -europe.weather 2 -europe.weather 3 -europe.weather 3 -europe.weather 4 -europe.weather 4 -usa.news 0 -usa.news 0 -usa.news 1 -usa.news 1 -usa.news 2 -usa.news 2 -usa.news 3 -usa.news 3 -usa.news 4 -usa.news 4 -usa.weather 0 -usa.weather 0 -usa.weather 1 -usa.weather 1 -usa.weather 2 -usa.weather 2 -usa.weather 3 -usa.weather 3 -usa.weather 4 -usa.weather 4 diff --git a/qpid/python/examples/request-response/client.py b/qpid/python/examples/request-response/client.py deleted file mode 100755 index b29fcf3ea7..0000000000 --- a/qpid/python/examples/request-response/client.py +++ /dev/null @@ -1,131 +0,0 @@ -#!/usr/bin/env python -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -""" - client.py - - Client for a client/server example - -""" - -import qpid -import sys -import os -from qpid.util import connect -from qpid.connection import Connection -from qpid.datatypes import Message, RangedSet, uuid4 -from qpid.queue import Empty - -#----- Functions ------------------------------------------- - -def dump_queue(queue_name): - - print "Messages on queue: " + queue_name - - message = 0 - - while True: - try: - message = queue.get(timeout=10) - content = message.body - session.message_accept(RangedSet(message.id)) - print "Response: " + content - except Empty: - print "No more messages!" - break - except: - print "Unexpected exception!" - break - - -#----- Initialization -------------------------------------- - - -# Set parameters for login - -host="127.0.0.1" -port=5672 -user="guest" -password="guest" - -# If an alternate host or port has been specified, use that instead -# (this is used in our unit tests) -if len(sys.argv) > 1 : - host=sys.argv[1] -if len(sys.argv) > 2 : - port=int(sys.argv[2]) - -# Create a connection. -socket = connect(host, port) -connection = Connection (sock=socket, username=user, password=password) -connection.start() -session = connection.session(str(uuid4())) - - -#----- Main Body -- ---------------------------------------- - -# Create a response queue for the server to send responses to. Use the -# same string as the name of the queue and the name of the routing -# key. - -reply_to = "reply_to:" + session.name -session.queue_declare(queue=reply_to, exclusive=True) -session.exchange_bind(exchange="amq.direct", queue=reply_to, binding_key=reply_to) - -# Create a local queue and subscribe it to the response queue - -local_queue_name = "local_queue" -queue = session.incoming(local_queue_name) - -# Call message_subscribe() to tell the broker to deliver messages from -# the server's reply_to queue to our local client queue. The server -# will start delivering messages as soon as message credit is -# available. - -session.message_subscribe(queue=reply_to, destination=local_queue_name) -queue.start() - -# Send some messages to the server's request queue - -lines = ["Twas brillig, and the slithy toves", - "Did gyre and gimble in the wabe.", - "All mimsy were the borogroves,", - "And the mome raths outgrabe."] - -# We will use the same reply_to and routing key -# for each message - -message_properties = session.message_properties() -message_properties.reply_to = session.reply_to("amq.direct", reply_to) -delivery_properties = session.delivery_properties(routing_key="request") - -for line in lines: - print "Request: " + line - session.message_transfer(destination="amq.direct", message=Message(message_properties, delivery_properties, line)) - -# Now see what messages the server sent to our reply_to queue - -dump_queue(reply_to) - - -#----- Cleanup ------------------------------------------------ - -# Clean up before exiting so there are no open threads. - -session.close(timeout=10) diff --git a/qpid/python/examples/request-response/server.py b/qpid/python/examples/request-response/server.py deleted file mode 100755 index a80c4541e4..0000000000 --- a/qpid/python/examples/request-response/server.py +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/env python -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -""" - server.py - - Server for a client/server example -""" - -import qpid -import sys -import os -from qpid.util import connect -from qpid.connection import Connection -from qpid.datatypes import Message, RangedSet, uuid4 -from qpid.queue import Empty - -#----- Functions ------------------------------------------- -def respond(session, request): - - # The routing key for the response is the request's reply-to - # property. The body for the response is the request's body, - # converted to upper case. - - message_properties = request.get("message_properties") - reply_to = message_properties.reply_to - if reply_to == None: - raise Exception("This message is missing the 'reply_to' property, which is required") - - props = session.delivery_properties(routing_key=reply_to["routing_key"]) - session.message_transfer(destination=reply_to["exchange"], message=Message(props,request.body.upper())) - -#----- Initialization -------------------------------------- - - -# Set parameters for login - -host="127.0.0.1" -port=5672 -user="guest" -password="guest" - -# If an alternate host or port has been specified, use that instead -# (this is used in our unit tests) -if len(sys.argv) > 1 : - host=sys.argv[1] -if len(sys.argv) > 2 : - port=int(sys.argv[2]) - -socket = connect(host, port) -connection = Connection (sock=socket, username=user, password=password) -connection.start() -session = connection.session(str(uuid4())) - -#----- Main Body -- ---------------------------------------- - -# Create a request queue and subscribe to it - -session.queue_declare(queue="request", exclusive=True) -session.exchange_bind(exchange="amq.direct", queue="request", binding_key="request") - -local_queue_name = "local_queue" - -session.message_subscribe(queue="request", destination=local_queue_name) - -queue = session.incoming(local_queue_name) -queue.start() - -# Remind the user to start the client program - -print "Request server running - run your client now." -print "(Times out after 100 seconds ...)" -sys.stdout.flush() - -# Respond to each request - -# If we get a message, send it back to the user (as indicated in the -# ReplyTo property) - -while True: - try: - request = queue.get(timeout=100) - respond(session, request) - session.message_accept(RangedSet(request.id)) - except Empty: - print "No more messages!" - break; - - -#----- Cleanup ------------------------------------------------ - -# Clean up before exiting so there are no open threads. - -session.close(timeout=10) diff --git a/qpid/python/examples/request-response/verify b/qpid/python/examples/request-response/verify deleted file mode 100644 index 3c058febb2..0000000000 --- a/qpid/python/examples/request-response/verify +++ /dev/null @@ -1,24 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -background "Request server running" ./server.py -clients ./client.py -kill %% # Must kill the server. -outputs "./client.py.out | remove_uuid" " server.py.out | remove_uuid" diff --git a/qpid/python/examples/request-response/verify.in b/qpid/python/examples/request-response/verify.in deleted file mode 100644 index 4c31128975..0000000000 --- a/qpid/python/examples/request-response/verify.in +++ /dev/null @@ -1,14 +0,0 @@ -==== client.py.out | remove_uuid -Request: Twas brillig, and the slithy toves -Request: Did gyre and gimble in the wabe. -Request: All mimsy were the borogroves, -Request: And the mome raths outgrabe. -Messages on queue: reply_to: -Response: TWAS BRILLIG, AND THE SLITHY TOVES -Response: DID GYRE AND GIMBLE IN THE WABE. -Response: ALL MIMSY WERE THE BOROGROVES, -Response: AND THE MOME RATHS OUTGRABE. -No more messages! -==== server.py.out | remove_uuid -Request server running - run your client now. -(Times out after 100 seconds ...) diff --git a/qpid/python/examples/xml-exchange/declare_queues.py b/qpid/python/examples/xml-exchange/declare_queues.py deleted file mode 100755 index ca40af5dc5..0000000000 --- a/qpid/python/examples/xml-exchange/declare_queues.py +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env python -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -""" - declare_queues.py - - Creates and binds a queue on an AMQP direct exchange. - - All messages using the routing key "routing_key" are - sent to the queue named "message_queue". -""" - -import qpid -import sys -import os -from qpid.util import connect -from qpid.connection import Connection -from qpid.datatypes import Message, RangedSet, uuid4 -from qpid.queue import Empty - -#----- Initialization ----------------------------------- - - -# Set parameters for login - -host="127.0.0.1" -port=5672 -user="guest" -password="guest" - -# If an alternate host or port has been specified, use that instead -# (this is used in our unit tests) -if len(sys.argv) > 1 : - host=sys.argv[1] -if len(sys.argv) > 2 : - port=int(sys.argv[2]) - -# Create a connection. -socket = connect(host, port) -connection = Connection (sock=socket, username=user, password=password) -connection.start() -session = connection.session(str(uuid4())) - -#----- Create a queue ------------------------------------- - -# queue_declare() creates an AMQP queue, which is held -# on the broker. Published messages are sent to the AMQP queue, -# from which messages are delivered to consumers. -# -# queue_bind() determines which messages are routed to a queue. -# Route all messages with the routing key "routing_key" to -# the AMQP queue named "message_queue". - -session.exchange_declare(exchange="xml", type="xml") -session.queue_declare(queue="message_queue") - -binding = {} -binding["xquery"] = """ - let $w := ./weather - return $w/station = 'Raleigh-Durham International Airport (KRDU)' - and $w/temperature_f > 50 - and $w/temperature_f - $w/dewpoint > 5 - and $w/wind_speed_mph > 7 - and $w/wind_speed_mph < 20 """ - - -session.exchange_bind(exchange="xml", queue="message_queue", binding_key="weather", arguments=binding) - - -#----- Cleanup --------------------------------------------- - -session.close() - - diff --git a/qpid/python/examples/xml-exchange/listener.py b/qpid/python/examples/xml-exchange/listener.py deleted file mode 100755 index a56f5d6018..0000000000 --- a/qpid/python/examples/xml-exchange/listener.py +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env python -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -""" - listener.py - - This AMQP client reads messages from a message - queue named "message_queue". It is implemented - as a message listener. -""" - - -import qpid -import sys -import os -from qpid.util import connect -from qpid.connection import Connection -from qpid.datatypes import Message, RangedSet, uuid4 -from qpid.queue import Empty - -# - -from time import sleep - - -#----- Message Receive Handler ----------------------------- -class Receiver: - def __init__ (self): - self.finalReceived = False - - def isFinal (self): - return self.finalReceived - - def Handler (self, message): - content = message.body - session.message_accept(RangedSet(message.id)) - print content - -#----- Initialization -------------------------------------- - -# Set parameters for login - -host="127.0.0.1" -port=5672 -user="guest" -password="guest" - -# If an alternate host or port has been specified, use that instead -# (this is used in our unit tests) -if len(sys.argv) > 1 : - host=sys.argv[1] -if len(sys.argv) > 2 : - port=int(sys.argv[2]) - -# Create a connection. -socket = connect(host, port) -connection = Connection (sock=socket, username=user, password=password) -connection.start() -session = connection.session(str(uuid4())) - -#----- Read from queue -------------------------------------------- - -# Now let's create a local client queue and tell it to read -# incoming messages. - -# The consumer tag identifies the client-side queue. - -local_queue_name = "local_queue" -local_queue = session.incoming(local_queue_name) - -# Call message_subscribe() to tell the broker to deliver messages -# from the AMQP queue to this local client queue. The broker will -# start delivering messages as soon as local_queue.start() is called. - -session.message_subscribe(queue="message_queue", destination=local_queue_name) -local_queue.start() - -receiver = Receiver () -local_queue.listen (receiver.Handler) - -sleep (10) - - -#----- Cleanup ------------------------------------------------ - -# Clean up before exiting so there are no open threads. -# - -session.close() diff --git a/qpid/python/examples/xml-exchange/verify b/qpid/python/examples/xml-exchange/verify deleted file mode 100644 index a93a32dc90..0000000000 --- a/qpid/python/examples/xml-exchange/verify +++ /dev/null @@ -1,22 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -clients ./declare_queues.py ./xml_producer.py ./xml_consumer.py -outputs ./declare_queues.py.out ./xml_producer.py.out ./xml_consumer.py.out diff --git a/qpid/python/examples/xml-exchange/verify.in b/qpid/python/examples/xml-exchange/verify.in deleted file mode 100644 index e5b9909408..0000000000 --- a/qpid/python/examples/xml-exchange/verify.in +++ /dev/null @@ -1,15 +0,0 @@ -==== declare_queues.py.out -==== xml_producer.py.out -Raleigh-Durham International Airport (KRDU)03035 -New Bern, Craven County Regional Airport (KEWN)24040 -Boone, Watauga County Hospital Heliport (KTNB)55045 -Hatteras, Mitchell Field (KHSE)106050 -Raleigh-Durham International Airport (KRDU)167035 -New Bern, Craven County Regional Airport (KEWN)228040 -Boone, Watauga County Hospital Heliport (KTNB)289045 -Hatteras, Mitchell Field (KHSE)3510050 -Raleigh-Durham International Airport (KRDU)423035 -New Bern, Craven County Regional Airport (KEWN)514040 -==== xml_consumer.py.out -Raleigh-Durham International Airport (KRDU)167035 -No more messages! diff --git a/qpid/python/examples/xml-exchange/xml_consumer.py b/qpid/python/examples/xml-exchange/xml_consumer.py deleted file mode 100755 index cd89110b05..0000000000 --- a/qpid/python/examples/xml-exchange/xml_consumer.py +++ /dev/null @@ -1,96 +0,0 @@ -#!/usr/bin/env python -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -""" - direct_consumer.py - - This AMQP client reads messages from a message - queue named "message_queue". -""" - -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, RangedSet, uuid4 -from qpid.queue import Empty - - -#----- Initialization -------------------------------------- - -# Set parameters for login - -host="127.0.0.1" -port=5672 -user="guest" -password="guest" - -# If an alternate host or port has been specified, use that instead -# (this is used in our unit tests) -if len(sys.argv) > 1 : - host=sys.argv[1] -if len(sys.argv) > 2 : - port=int(sys.argv[2]) - -# Create a connection. -socket = connect(host, port) -connection = Connection (sock=socket, username=user, password=password) -connection.start() -session = connection.session(str(uuid4())) - - -#----- Read from queue -------------------------------------------- - -# Now let's create a local client queue and tell it to read -# incoming messages. - -# The consumer tag identifies the client-side queue. - -local_queue_name = "local_queue" -local_queue = session.incoming(local_queue_name) - -# Call message_consume() to tell the broker to deliver messages -# from the AMQP queue to this local client queue. The broker will -# start delivering messages as soon as local_queue.start() is called. - -session.message_subscribe(queue="message_queue", destination=local_queue_name) -local_queue.start() - -# Initialize 'final' and 'content', variables used to identify the last message. - -message = None -while True: - try: - message = local_queue.get(timeout=10) - session.message_accept(RangedSet(message.id)) - content = message.body - print content - except Empty: - print "No more messages!" - break - - -#----- Cleanup ------------------------------------------------ - -# Clean up before exiting so there are no open threads. -# - -session.close() diff --git a/qpid/python/examples/xml-exchange/xml_producer.py b/qpid/python/examples/xml-exchange/xml_producer.py deleted file mode 100755 index fa97cab4e1..0000000000 --- a/qpid/python/examples/xml-exchange/xml_producer.py +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env python -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -""" - xml_producer.py - - Publishes messages to an XML exchange, using - the routing key "weather" -""" - - -import qpid -import sys -import os -from qpid.util import connect -from qpid.connection import Connection -from qpid.datatypes import Message, RangedSet, uuid4 -from qpid.queue import Empty - -#----- Functions ---------------------------------------- - -# Data for weather reports - -station = ("Raleigh-Durham International Airport (KRDU)", - "New Bern, Craven County Regional Airport (KEWN)", - "Boone, Watauga County Hospital Heliport (KTNB)", - "Hatteras, Mitchell Field (KHSE)") -wind_speed_mph = ( 0, 2, 5, 10, 16, 22, 28, 35, 42, 51, 61, 70, 80 ) -temperature_f = ( 30, 40, 50, 60, 70, 80, 90, 100 ) -dewpoint = ( 35, 40, 45, 50 ) - -def pick_one(list, i): - return str( list [ i % len(list)] ) - -def report(i): - return "" + "" + pick_one(station,i)+ "" + "" + pick_one(wind_speed_mph,i) + "" + "" + pick_one(temperature_f,i) + "" + "" + pick_one(dewpoint,i) + "" + "" - - -#----- Initialization ----------------------------------- - -# Set parameters for login - -host="127.0.0.1" -port=5672 -user="guest" -password="guest" - -# If an alternate host or port has been specified, use that instead -# (this is used in our unit tests) -if len(sys.argv) > 1 : - host=sys.argv[1] -if len(sys.argv) > 2 : - port=int(sys.argv[2]) - -# Create a connection. -socket = connect(host, port) -connection = Connection (sock=socket, username=user, password=password) -connection.start() -session = connection.session(str(uuid4())) - -#----- Publish some messages ------------------------------ - -# Create some messages and put them on the broker. - -props = session.delivery_properties(routing_key="weather") - -for i in range(10): - print report(i) - session.message_transfer(destination="xml", message=Message(props, report(i))) - - -#----- Cleanup -------------------------------------------- - -# Clean up before exiting so there are no open threads. - -session.close() -- cgit v1.2.1 From 92dc1f32c9c4258ee6a65a5106d92600e396f683 Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Tue, 13 Jul 2010 17:43:48 +0000 Subject: corrected whitespace git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@963800 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/README.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/README.txt b/qpid/python/examples/README.txt index 50bb0a8c9b..4395160fec 100644 --- a/qpid/python/examples/README.txt +++ b/qpid/python/examples/README.txt @@ -17,7 +17,6 @@ api/spout -- A simple messaging client that sends api/server -- An example server that process incoming messages and sends replies. - api/hello -- An example client that sends a message and then receives it. @@ -25,6 +24,7 @@ api/hello_xml -- An example client that sends a message to the xml exchange and then receives it. + reservations -- Directory containing an example machine reservation system. -- cgit v1.2.1 From 4b67ae91be27048aca8ded77b1089dd0487eff03 Mon Sep 17 00:00:00 2001 From: Jonathan Robie Date: Mon, 9 Aug 2010 16:34:04 +0000 Subject: Changed conditional assignment to vanilla if/then/else, for compatibility with older Python. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@983718 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/api/hello | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/api/hello b/qpid/python/examples/api/hello index 4644189941..a220fe794e 100755 --- a/qpid/python/examples/api/hello +++ b/qpid/python/examples/api/hello @@ -21,8 +21,15 @@ import sys from qpid.messaging import * -broker = "localhost:5672" if len(sys.argv)<2 else sys.argv[1] -address = "amq.topic" if len(sys.argv)<3 else sys.argv[2] +if len(sys.argv)<2: + broker = "localhost:5672" +else: + broker = sys.argv[1] + +if len(sys.argv)<3: + address = "amq.topic" +else: + address = sys.argv[2] connection = Connection(broker) -- cgit v1.2.1 From e3bc2893e6a3fae16079ba7bdcb034f3026fee76 Mon Sep 17 00:00:00 2001 From: Jonathan Robie Date: Mon, 9 Aug 2010 17:31:40 +0000 Subject: Removed finally - Python before 2.5 did not allow finally together with specific exceptions. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@983743 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/examples/api/hello | 4 ++-- qpid/python/examples/api/hello_xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'qpid/python/examples') diff --git a/qpid/python/examples/api/hello b/qpid/python/examples/api/hello index a220fe794e..ad314da19e 100755 --- a/qpid/python/examples/api/hello +++ b/qpid/python/examples/api/hello @@ -48,5 +48,5 @@ try: except MessagingError,m: print m -finally: - connection.close() + +connection.close() diff --git a/qpid/python/examples/api/hello_xml b/qpid/python/examples/api/hello_xml index 07c2b13120..ab567ec5dd 100755 --- a/qpid/python/examples/api/hello_xml +++ b/qpid/python/examples/api/hello_xml @@ -73,5 +73,5 @@ try: except MessagingError,m: print m -finally: - connection.close() + +connection.close() -- cgit v1.2.1