Closed mohanrajanna15 closed 3 months ago
Team, Can anyone please review this and let us know what can we do here.
can you do catch the rabbitmq disconnections and reestablish rabbitmq connection
The below code perhaps can give you some input (not tested)
const amqp = require('amqplib');
const rabbitMQUrl = 'amqp://localhost';
async function setup() {
try {
// Connect to RabbitMQ
const connection = await amqp.connect(rabbitMQUrl);
const channel = await connection.createChannel();
// Declare a queue
const queueName = 'exampleQueue';
await channel.assertQueue(queueName, { durable: false });
// Simulate an error (comment this line if you want to see error recovery in action)
throw new Error('Simulated error');
// Send a message to the queue
const message = 'Hello, RabbitMQ!';
await channel.sendToQueue(queueName, Buffer.from(message));
console.log(`Sent message: ${message}`);
// Close the channel and connection
await channel.close();
await connection.close();
} catch (error) {
// Handle RabbitMQ errors
console.error('RabbitMQ Error:', error.message);
// Perform error recovery here
// For example, you can implement a reconnection strategy
// Uncomment the following lines to implement a reconnection strategy
console.log('Reconnecting to RabbitMQ...');
setTimeout(setup, 5000); // Retry the setup function after a delay
}
}
// Start the setup function
setup();
It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.
Version
16.20.1
Platform
Darwin Rajanna-MacBook-Pro.local 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:08:47 PST 2022; root:xnu-8792.61.2~4/RELEASE_X86_64 x86_64
Subsystem
No response
What steps will reproduce the bug?
There is no accurate STR however, our node app uses rabbitmq client to transact certain messages between endpoints.
What we have noticed is when rabbitmq throws an errors where its shutting down a channel due to some errors, we have seen node process running our app gets crashed hence our app gets crashed. I inspected the portion of code and don't see a catch block to report the exception hence the node is crashing with unhandled exception (node:internal/process/task_queues:82:21) . Here is the stacktrace, we need someone to at least let us know how to avoid this as this is hurting our production systems.
How often does it reproduce? Is there a required condition?
Every now and then
What is the expected behavior? Why is that the expected behavior?
Node should not crash
What do you see instead?
Node is crashing.
Additional information
No response