Skip to content

Commit 2a753d4

Browse files
author
DanielePalaia
committed
few improvements
1 parent 54d0715 commit 2a753d4

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

rabbitmq_amqp_python_client/connection.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ def consumer(
278278

279279
def _on_disconnection(self) -> None:
280280

281+
logger.debug("_on_disconnection: disconnection detected")
281282
if self in self._connections:
282283
self._connections.remove(self)
283284

@@ -286,6 +287,7 @@ def _on_disconnection(self) -> None:
286287

287288
for attempt in range(self._recovery_configuration.MaxReconnectAttempts): # type: ignore
288289

290+
logger.debug("attempting a reconnection")
289291
jitter = timedelta(milliseconds=random.randint(0, 500))
290292
delay = base_delay + jitter
291293

@@ -318,16 +320,24 @@ def _on_disconnection(self) -> None:
318320

319321
except ConnectionException as e:
320322
base_delay *= 2
321-
logger.error(
323+
logger.debug(
322324
"Reconnection attempt failed",
323325
"attempt",
324326
attempt,
325327
"error",
326328
str(e),
327329
)
328-
continue
330+
# maximum attempts reached without establishing a connection
331+
if attempt == self._recovery_configuration.MaxReconnectAttempts - 1: # type: ignore
332+
logger.debug("Not able to reconnect")
333+
raise ConnectionException
334+
else:
335+
continue
329336

330-
break
337+
# connection established
338+
else:
339+
logger.debug("reconnected successful")
340+
return
331341

332342
@property
333343
def active_producers(self) -> int:

rabbitmq_amqp_python_client/entities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,5 +231,5 @@ class RecoveryConfiguration:
231231
"""
232232

233233
active_recovery: bool = True
234-
back_off_reconnect_interval: timedelta = timedelta(0.5)
234+
back_off_reconnect_interval: timedelta = timedelta(seconds=5)
235235
MaxReconnectAttempts: int = 5

rabbitmq_amqp_python_client/qpid/proton/_tracing.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@
3232

3333
import proton
3434
from proton import Sender as ProtonSender
35-
from proton.handlers import \
36-
IncomingMessageHandler as ProtonIncomingMessageHandler
37-
from proton.handlers import \
38-
OutgoingMessageHandler as ProtonOutgoingMessageHandler
35+
from proton.handlers import IncomingMessageHandler as ProtonIncomingMessageHandler
36+
from proton.handlers import OutgoingMessageHandler as ProtonOutgoingMessageHandler
3937

4038
_tracer = None
4139
_trace_key = proton.symbol("x-opt-qpid-tracestate")

rabbitmq_amqp_python_client/qpid/proton/_transport.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@
139139

140140
if TYPE_CHECKING:
141141
from ._condition import Condition
142-
from ._endpoints import \
143-
Connection # would produce circular import
142+
from ._endpoints import Connection # would produce circular import
144143

145144

146145
class TraceAdapter:

0 commit comments

Comments
 (0)