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