-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
Connection retry? #67
Comments
Hey @murbanowicz I think it makes sense for this to be natively supported by the module. How do you currently implement retry/reconnection behavior in your RabbitMQ connected applications? Maybe if you share a snippet I can use that as a starting point |
Hi, I've done it in fairly simple way: async connectToAmqp(retry = 1): Promise<amqplib.Connection> {
if (retry > this.config.maxRetries) {
this.logger.error('Maximum AMQP connection retries reached!');
throw new Error('Maximum AMQP connection retries reached!');
}
this.logger.debug(`Connecting to AMQP. ${retry} try.`);
try {
const connection = await amqplib.connect(this.config.uri);
connection.on('close', async () => {
this.readiness = false;
this.logger.warn('AMQP disconnected. Will try to reconnect...');
this.connection = await this.connectToAmqp();
});
this.readiness = true;
return connection;
} catch (e) {
this.logger.debug(`Could not connect to AMQP.`, e);
await waitFor(this.config.reconnectDelay * retry);
return this.connectToAmqp(retry + 1);
}
} |
Thanks for the example code, I'll try to incorporate improved retry and connection logic into the library in the coming week |
I recommend you consider incorporating amqp-connection-manager - https://www.npmjs.com/package/amqp-connection-manager |
I created a PR for that if you're interested - #80 |
Connection management is now possible thanks to amqp-connection-manager and the awesome contributions from @azuker |
Hi,
It is a really nice module but it is missing connection retry on init or on error.
Are you interested in implementing this feature?
The text was updated successfully, but these errors were encountered: