diff options
author | Rafael H. Schloming <rhs@apache.org> | 2010-04-01 21:36:56 +0000 |
---|---|---|
committer | Rafael H. Schloming <rhs@apache.org> | 2010-04-01 21:36:56 +0000 |
commit | de5ca86b1cad3f879ffea1a0af0a58c7a8560d02 (patch) | |
tree | e95d8e36cfed53f9dca8c07abbe736fa63f016b2 | |
parent | e63d139b7f275d2271d4a5f15b9894836ab1e371 (diff) | |
download | qpid-python-de5ca86b1cad3f879ffea1a0af0a58c7a8560d02.tar.gz |
added option to disable reconnect logging; fixed reconnect test to not loop forever if no broker is running; backups -> reconnect_hosts
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@930105 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | python/qpid/messaging/driver.py | 14 | ||||
-rw-r--r-- | python/qpid/messaging/endpoints.py | 2 | ||||
-rw-r--r-- | python/qpid/messaging/util.py | 20 | ||||
-rw-r--r-- | python/qpid/tests/messaging/endpoints.py | 2 |
4 files changed, 21 insertions, 17 deletions
diff --git a/python/qpid/messaging/driver.py b/python/qpid/messaging/driver.py index e9058d8154..7b165ec94b 100644 --- a/python/qpid/messaging/driver.py +++ b/python/qpid/messaging/driver.py @@ -325,7 +325,8 @@ class Driver: self._attempts = 0 self._delay = self.connection.reconnect_interval_min self._hosts = [(self.connection.host, self.connection.port)] + \ - self.connection.backups + self.connection.reconnect_hosts + self._reconnect_log = self.connection.options.get("reconnect_log", True) self._host = 0 self._retrying = False self._transport = None @@ -395,9 +396,10 @@ class Driver: self._delay = min(2*self._delay, self.connection.reconnect_interval_max) self._timeout = time.time() + delay - log.warn("recoverable error[attempt %s]: %s" % (self._attempts, e)) - if delay > 0: - log.warn("sleeping %s seconds" % delay) + if self._reconnect_log: + log.warn("recoverable error[attempt %s]: %s" % (self._attempts, e)) + if delay > 0: + log.warn("sleeping %s seconds" % delay) self._retrying = True self.engine.close() else: @@ -456,7 +458,7 @@ class Driver: if self._host == 0: self._attempts += 1 host, port = self._hosts[self._host] - if self._retrying: + if self._retrying and self._reconnect_log: log.warn("trying: %s:%s", host, port) self.engine = Engine(self.connection) self.engine.open() @@ -466,7 +468,7 @@ class Driver: self._transport = trans(host, port) else: raise ConnectError("no such transport: %s" % self.connection.transport) - if self._retrying: + if self._retrying and self._reconnect_log: log.warn("reconnect succeeded: %s:%s", host, port) self._timeout = None self._attempts = 0 diff --git a/python/qpid/messaging/endpoints.py b/python/qpid/messaging/endpoints.py index fd5dc35a42..be07c0818f 100644 --- a/python/qpid/messaging/endpoints.py +++ b/python/qpid/messaging/endpoints.py @@ -94,8 +94,8 @@ class Connection: else: self.reconnect_interval_max = options.get("reconnect_interval", 2*60) self.reconnect_limit = options.get("reconnect_limit") + self.reconnect_hosts = options.get("reconnect_hosts", []) self.transport = options.get("transport", "plain") - self.backups = options.get("backups", []) self.options = options if self.transport == "tls": diff --git a/python/qpid/messaging/util.py b/python/qpid/messaging/util.py index 12c02475f0..30b54f3ad4 100644 --- a/python/qpid/messaging/util.py +++ b/python/qpid/messaging/util.py @@ -26,31 +26,31 @@ from threading import Thread log = getLogger("qpid.messaging.util") -def auto_update_backups(conn): - ssn = conn.session("auto-update-backups") +def auto_fetch_reconnect_hosts(conn): + ssn = conn.session("auto-fetch-reconnect-hosts") rcv = ssn.receiver("amq.failover") rcv.capacity = 10 def main(): while True: msg = rcv.fetch() - update_backups(conn, msg) + set_reconnect_hosts(conn, msg) ssn.acknowledge(msg, sync=False) - thread = Thread(name="auto-update-backups", target=main) + thread = Thread(name="auto-fetch-reconnect-hosts", target=main) thread.setDaemon(True) thread.start() -def update_backups(conn, msg): - backups = [] +def set_reconnect_hosts(conn, msg): + reconnect_hosts = [] urls = msg.properties["amq.failover"] for u in urls: if u.startswith("amqp:tcp:"): parts = u.split(":") host, port = parts[2:4] - backups.append((host, port)) - conn.backups = backups - log.warn("updated backups for conn %s: %s", conn, backups) + reconnect_hosts.append((host, port)) + conn.reconnect_hosts = reconnect_hosts + log.warn("set reconnect_hosts for conn %s: %s", conn, reconnect_hosts) -__all__ = ["auto_update_backups", "update_backups"] +__all__ = ["auto_fetch_reconnect_hosts", "set_reconnect_hosts"] diff --git a/python/qpid/tests/messaging/endpoints.py b/python/qpid/tests/messaging/endpoints.py index a849957374..a6c7046d01 100644 --- a/python/qpid/tests/messaging/endpoints.py +++ b/python/qpid/tests/messaging/endpoints.py @@ -116,6 +116,8 @@ class SetupTests(Base): options["reconnect"] = True options["reconnect_interval"] = 0 + options["reconnect_limit"] = 100 + options["reconnect_log"] = False options["transport"] = "flaky" self.conn = Connection.open(self.broker.host, self.broker.port, **options) |