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/api') 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/api') 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/api') 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/api') 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/api') 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') 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/api') 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 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/api') 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/api') 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/api') 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 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') 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/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/api') 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/api') 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/api') 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 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/api') 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/api') 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/api') 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/api') 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 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/api') 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/api') 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