Skip to content

Commit

Permalink
moved create_connection as a separate function in AsyncConsumer
Browse files Browse the repository at this point in the history
  • Loading branch information
kirgrim committed Nov 22, 2024
1 parent e629a59 commit 558f131
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion neon_mq_connector/aio/consumer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
from typing import Optional

import aio_pika
Expand Down Expand Up @@ -38,13 +39,24 @@ def __init__(
self.exchange_type = exchange_type or ExchangeType.DIRECT.value
self._is_consuming = False
self._is_consumer_alive = True
self.event_loop = asyncio.new_event_loop()

async def create_connection(self):
return await aio_pika.connect_robust(
host=self.connection_params.host,
port=self.connection_params.port,
login=self.connection_params.username,
password=self.connection_params.password,
virtualhost=self.connection_params.virtual_host,
loop=self.event_loop,
)

async def connect(self) -> None:
"""
Utilises aio-pika as a base interface for establishing async MQ connection
Upon establishing connection, declares queue and exchange if applicable
"""
self.connection = await aio_pika.connect_robust(**self.connection_params)
self.connection = await self.create_connection()
self.channel = await self.connection.channel()
await self.channel.set_qos(prefetch_count=50)
if self.queue_reset:
Expand Down

0 comments on commit 558f131

Please sign in to comment.