Skip to content

Commit

Permalink
Explicitly pass io_loop to SelectConnection to troubleshoot https:/…
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonDaniel committed Jan 16, 2025
1 parent 96b1c88 commit 28e4330
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions neon_mq_connector/consumers/select_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,15 @@ def __init__(self,
self.max_connection_failed_attempts = 3

def create_connection(self) -> pika.SelectConnection:
try:
io_loop = get_event_loop()
except RuntimeError:
io_loop = new_event_loop()
return pika.SelectConnection(parameters=self.connection_params,
on_open_callback=self.on_connected,
on_open_error_callback=self.on_connection_fail,
on_close_callback=self.on_close,)
on_close_callback=self.on_close,
custom_ioloop=io_loop)

def on_connected(self, _):
"""Called when we are fully connected to RabbitMQ"""
Expand Down Expand Up @@ -203,12 +208,6 @@ def is_consuming(self) -> bool:

def run(self):
"""Starting connection io loop """
try:
if get_event_loop() is None:
set_event_loop(new_event_loop())
except RuntimeError:
set_event_loop(new_event_loop())

if not self.is_consuming:
try:
self.connection: pika.SelectConnection = self.create_connection()
Expand Down

0 comments on commit 28e4330

Please sign in to comment.