Skip to content

Commit 42cad64

Browse files
author
Vikas Pandey
committed
added constant retry for of 5 seconds
1 parent 4d7ffdd commit 42cad64

File tree

2 files changed

+3
-24
lines changed

2 files changed

+3
-24
lines changed

rmq/rmqproducer/rabbitmq_producer.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class Publisher(object):
2020
2121
"""
2222

23-
prev_backoff = 1
2423

2524
def __init__(self, amqp_url, exchange, **kwargs):
2625
"""Create a new instance of the Publisher class, passing in the
@@ -69,7 +68,6 @@ def __init__(self, amqp_url, exchange, **kwargs):
6968
self.parse_input_args(kwargs)
7069
self.connect()
7170
self.run()
72-
self.prev_backoff = 1
7371

7472
def parse_input_args(self, kwargs):
7573
"""Parse and set connection parameters from a dictionary.
@@ -127,19 +125,9 @@ def on_connection_open(self, unused_connection):
127125
self._LOGGER.info('Connection opened')
128126
self.add_on_connection_close_callback()
129127
self.open_channel()
130-
self.prev_backoff = 1
131-
132-
"""
133-
def get_retry_time(self):
134-
backoff = min(30, self.prev_backoff*2)
135-
retry_after = randint(1, backoff)
136-
self.prev_backoff = backoff
137-
return retry_after
138-
"""
139-
140-
128+
129+
141130
def on_connection_error(self, connection, error):
142-
#retry_time = self.get_retry_time()
143131
self._LOGGER.warning("Publisher: Connection lost retrying in {time}".format(time=5))
144132
connection.add_timeout(5, self.reconnect)
145133

rmq/rmqreceiver/rabbitmq_receiver.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def __init__(self, consumer_callback, amqp_url, exchange, **kwargs):
6363
self._url = amqp_url
6464
self.exchange = exchange
6565
self.parse_input_args(kwargs)
66-
self.prev_backoff = 1
6766

6867
def parse_input_args(self, kwargs):
6968
"""Parse and set connection parameters from a dictionary.
@@ -112,7 +111,6 @@ def on_connection_open(self, unused_connection):
112111
self._LOGGER.info('Connection opened')
113112
self.add_on_connection_close_callback()
114113
self.open_channel()
115-
self.prev_backoff = 1
116114

117115
def add_on_connection_close_callback(self):
118116
"""Add a callback that will be invoked if RabbitMQ closes the connection
@@ -123,17 +121,10 @@ def add_on_connection_close_callback(self):
123121
self._LOGGER.info('Adding connection close callback')
124122
self._connection.add_on_close_callback(self.on_connection_closed)
125123

126-
"""
127-
def get_retry_time(self):
128-
backoff = min(30, self.prev_backoff*2)
129-
retry_after = randint(1, backoff)
130-
self.prev_backoff = backoff
131-
return retry_after
132-
"""
124+
133125

134126

135127
def on_connection_error(self, connection, error):
136-
#retry_time = self.get_retry_time()
137128
self._LOGGER.warning("Connection failed.Retrying in next 5 seconds")
138129
connection.add_timeout(5, self.reconnect)
139130

0 commit comments

Comments
 (0)