Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture Logging messages #431

Merged
merged 5 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ TBD

- Add support to change the Exchange Type for RabbitMQ. Default is 'topic',
but options like 'fanout' can now be supported
- Better handling of Pika errors

3.22.0
------
Expand Down
48 changes: 27 additions & 21 deletions brewtils/pika.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SSLOptions,
URLParameters,
)
from pika.exceptions import AMQPError
from pika.exceptions import AMQPError, ConnectionWrongStateError
from pika.spec import PERSISTENT_DELIVERY_MODE

from brewtils.errors import DiscardMessageException, RepublishRequestException
Expand Down Expand Up @@ -305,26 +305,29 @@ def run(self):
None
"""
while not self._panic_event.is_set():
self._connection = self.open_connection()
self._connection.ioloop.start()

if not self._panic_event.is_set():
if 0 <= self._max_reconnect_attempts <= self._reconnect_attempt:
self.logger.warning("Max connection failures, shutting down")
self._panic_event.set()
return

self.logger.warning(
"%s consumer has died, waiting %i seconds before reconnecting",
self._queue_name,
self._reconnect_timeout,
)
self._panic_event.wait(self._reconnect_timeout)
try:
self._connection = self.open_connection()
self._connection.ioloop.start()

if not self._panic_event.is_set():
if 0 <= self._max_reconnect_attempts <= self._reconnect_attempt:
self.logger.warning("Max connection failures, shutting down")
self._panic_event.set()
return

self.logger.warning(
"%s consumer has died, waiting %i seconds before reconnecting",
self._queue_name,
self._reconnect_timeout,
)
self._panic_event.wait(self._reconnect_timeout)

self._reconnect_attempt += 1
self._reconnect_timeout = min(
self._reconnect_timeout * 2, self._max_reconnect_timeout
)
self._reconnect_attempt += 1
self._reconnect_timeout = min(
self._reconnect_timeout * 2, self._max_reconnect_timeout
)
except ConnectionWrongStateError as ex:
self.logger.error("Error running consumer IO-loop: %s", ex)

def stop(self):
"""Cleanly shutdown
Expand Down Expand Up @@ -566,7 +569,10 @@ def on_connection_closed(self, connection, *args):
def open_channel(self):
"""Open a channel"""
self.logger.debug("Opening a new channel")
self._connection.channel(on_open_callback=self.on_channel_open)
try:
self._connection.channel(on_open_callback=self.on_channel_open)
except ConnectionWrongStateError as ex:
self.logger.error("Failure opening channel to consume messages: %s", ex)

def on_channel_open(self, channel):
"""Channel open success callback
Expand Down
Loading