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/spout | 103 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100755 qpid/python/examples/api/spout (limited to 'qpid/python/examples/api/spout') 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/api/spout') 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 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/api/spout') 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/spout | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'qpid/python/examples/api/spout') 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 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/spout | 52 +++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 24 deletions(-) (limited to 'qpid/python/examples/api/spout') 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/spout | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'qpid/python/examples/api/spout') 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 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/api/spout') 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 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/spout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qpid/python/examples/api/spout') 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/spout | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'qpid/python/examples/api/spout') 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/spout | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'qpid/python/examples/api/spout') 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 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/spout | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'qpid/python/examples/api/spout') 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