Skip to content

Commit

Permalink
fixed route_key bug, plus added connection checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Geary-Layne committed Oct 28, 2024
1 parent 7e25beb commit fc4a2b2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions python/idsse_common/idsse/common/rabbitmq_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,8 @@ def __init__(
def run(self):
logger.info('Starting publisher')
while self._is_running:
self.connection.process_data_events(time_limit=1)
if self.connection and self.connection.is_open:
self.connection.process_data_events(time_limit=1)

def publish(self, message: bytes, properties: BasicProperties = None, route_key: str = None):
"""
Expand Down Expand Up @@ -500,8 +501,8 @@ def stop(self):
logger.info("Stopping publisher")
self._is_running = False
# Wait until all the data events have been processed
self.connection.process_data_events(time_limit=1)
if self.connection.is_open:
if self.connection and self.connection.is_open:
self.connection.process_data_events(time_limit=1)
threadsafe_call(self.channel,
self.channel.close,
self.connection.close)
Expand Down Expand Up @@ -533,7 +534,7 @@ def _publish(
route_key = self._exch.route_key

self.channel.basic_publish(self._exch.name,
routing_key=route_key,
route_key if route_key else self._exch.route_key,
body=message,
properties=properties,
mandatory=self._exch.mandatory)
Expand Down

0 comments on commit fc4a2b2

Please sign in to comment.