-
Notifications
You must be signed in to change notification settings - Fork 192
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
Impossible to handle Unexpected connection close #599
Comments
You can use a regular connection instead of robust one. Also event |
What I also did is def on_connection_closed(self, *args, **kwargs):
sys.exit(1) async def init(self) -> None:
import settings
logger.info("Initializing AMQP handler")
config = settings.BaseMessageBrokerSettings
conn = await aiormq.connect(
config.get_dsn(),
loop=asyncio.get_event_loop(),
)
channel = await conn.channel()
conn.closing.add_done_callback(self.on_connection_closed)
channel.closing.add_done_callback(self.on_connection_closed)
await channel.exchange_declare(
exchange=config.EXCHANGE_NAME,
exchange_type=config.EXCHANGE_TYPE,
auto_delete=config.EXCHANGE_AUTO_DELETE,
durable=True,
)
for key in config.BINDING_KEYS:
q_name = (
f"{key}.{config.PREFIX_BINDING_KEYS}"
if config.PREFIX_BINDING_KEYS
else key
)
queue = await channel.queue_declare(queue=q_name, durable=True)
self.queues.append(queue)
await channel.queue_bind(exchange=config.EXCHANGE_NAME, queue=q_name)
await channel.basic_consume(queue.queue, self.handle_message, no_ack=True)
logger.info("Queue declared", extra={"queue": q_name})
self.conn = conn
self.channel = channel
logger.info("AMQP handler initialized")
|
Your original code uses |
I have the same issue. With The logs show the consumer reconnecting every 5secs, Rabbit becomes reachable again, the logs stop and no new messages show up. In the UI RabbitMQ has 0 consumer for that I'm using the exact code from here (Master/Worker) but with a dict instead of @mosquito Any idea? I'm using the |
We're currently using aio_pika-9.4.2 and encountered the same issue with |
@yaelmi3 I fixed my issue using this #231 (comment) |
@yaelmi3 I have the same issue, connection stuck after RabbitMQ becames available again. I had code like
and then declaring a queue and etc. I added timeout argument to connect_robust function, and it works!
Now after rabbit becames alive I have TimeourError (seems that reconnect task stucks, if rabbit becomes alive during the reconnection process). And the next reconnection try has a success. |
@RomaLash : Actually I did try adding timeout to the My solution was changing the code in the following manner, inspired by this from @gaby Before:
After:
|
How to handle Unexpected connection close and raise an exception?
I've got the logic below:
Now, when Rabbit dropes, connection reconnects every 5 seconds. How to make it raise an exception which I could handle and stop a micro-service?
The text was updated successfully, but these errors were encountered: