Open
Description
I ran into this problem where I'd do and action that caused the server to close the channel Example: publishing to a missing exchange
. I expected the channel to be recreated but I get stuck with a closed/broken channel. If I cause a disconnection from Rabbitmq the channel gets recreated and everything works again.
Is this the expected behavior? Is there a better way of handling this case?
Here's an example with the workaround I'm using for the moment.
const amqp = require('amqp-connection-manager');
const client = amqp.connect('amqp://admin:admin@localhost:5672');
const channelWrapper = client.createChannel({
setup: (channel) => {
console.log('setup channel');
// add this hack to reconnect if the server closes the connection (workaround)
channel.on('close', () => {
if (channel.sendMessage === channel.sendOrEnqueue) {
channelWrapper._onConnect({connection: channelWrapper._connectionManager.connection});
}
});
setTimeout(async () => {
try {
await channel.publish('missing_exchange', '', Buffer.from('msg'));
} catch (err) {
console.log('published to wrong exchange server closes channel', err);
}
}, 1000);
return channel;
}
});
Metadata
Assignees
Labels
No labels