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/server | 80 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 qpid/python/examples/api/server (limited to 'qpid/python/examples/api/server') 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/server') 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 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/server | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'qpid/python/examples/api/server') 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) -- 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/server | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'qpid/python/examples/api/server') 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() -- 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/server | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qpid/python/examples/api/server') 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, -- 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/server | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'qpid/python/examples/api/server') 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") -- 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/server | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'qpid/python/examples/api/server') 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) -- 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/server | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'qpid/python/examples/api/server') 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") -- cgit v1.2.1