Fix RabbitMQ connection retry wrapper so it doesn't block for
indefinetly if connection to RabbitMQ cannot be established.
Also add errback which logs an actual error when trying to re-establish
a connection.
@@ -136,6 +136,7 @@ class ConnectionRetryWrapper(object):
raise
# -1, 0 and 1+ are handled properly by eventlet.sleep
+ wait = 1
self._logger.debug('Received RabbitMQ server error, sleeping for %s seconds '
'before retrying: %s' % (wait, str(e)))
eventlet.sleep(wait)
@@ -146,10 +147,21 @@ class ConnectionRetryWrapper(object):
# entire ConnectionPool simultaneously but that would require writing our own
# ConnectionPool. If a server recovers it could happen that the same process
# ends up talking to separate nodes in a cluster.
- connection.ensure_connection()
+ def log_error_on_conn_failure(exc, interval):
+ self._logger.debug('Failed to re-establish connection to RabbitMQ server: %s' %
+ (str(e)))
+
+ try:
+ # NOTE: This function blocks and tries to restablish a connection for
+ # indefinetly if "max_retries" argument is not specified
+ connection.ensure_connection(max_retries=5, errback=log_error_on_conn_failure)
+ except Exception:
+ self._logger.exception('Connections to RabbitMQ cannot be re-established: %s',
+ str(e))
+ raise
except Exception as e:
- self._logger.exception('Connections to rabbitmq cannot be re-established: %s',
+ self._logger.exception('Connections to RabbitMQ cannot be re-established: %s',
str(e))
# Not being able to publish a message could be a significant issue for an app.
raise
