Skip to content

Conversation

@federicsp
Copy link

Add RobustConnectionMultiHost class for fault-tolerant RabbitMQ connections:

  • Implements a connection class that tries multiple broker URLs in sequence until one succeeds.

  • Automatically handles reconnection on unexpected connection closures.

@federicsp
Copy link
Author

Going to add some tests

@federicsp
Copy link
Author

federicsp commented Jun 27, 2025

Fixes #141

super().__init__(str(self.urls[0]), **kwargs)

def _prepare_url(self, url: str, default_port: int) -> URL:
if not url.startswith("amqp://"):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about amqps?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should consider that! right, thanks

from aio_pika.robust_connection import RobustConnection
import asyncio

class RobustConnectionMultiHost(RobustConnection):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RobustConnectionRRHost semantically it is closer, because you connection is not a multihost, it is a round-robin retying to connect only to one.

Copy link
Author

@federicsp federicsp Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, thanks. I'm going to review the module and add some tests

await super()._on_connection_close(closing)

async def reconnect(self):
await asyncio.sleep(2)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 2? Why not 60 or 0.0001?

@coveralls
Copy link

Coverage Status

coverage: 89.779% (-1.9%) from 91.72%
when pulling fae412e on federicsp:feat/add_robust_connection_multihost
into c281314 on mosquito:master.

@federicsp federicsp force-pushed the feat/add_robust_connection_multihost branch from db67837 to fee1abe Compare July 1, 2025 19:42
@federicsp federicsp requested a review from mosquito July 1, 2025 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants