node-amqp-connection-manager icon indicating copy to clipboard operation
node-amqp-connection-manager copied to clipboard

channelWrapper.checkQueue caused connection disconnect, it should only bork the channel, not connection

Open shuidian opened this issue 2 years ago • 2 comments

this is my code:

const conn = await amqpConnManager.connect([options])
const ch =conn.createChannel()
await ch.waitForConnect()
ch.checkQueue('test-queue-name')

when queue is not exist this may cause connection disconnect. but in amqplib api(https://amqp-node.github.io/amqplib/channel_api.html#channel_checkQueue), checkQueue error only bork the channel,not connection.

shuidian avatar Aug 16 '22 03:08 shuidian

whew, I just encountered same error, waste me about two days or so... in case you still wondering the reason and solution, It seems like channelWrapper's event handler does not apply to underlying channel, so since you don't have .on('error') handler attach to channel, every channel exception will escape and cause your connection disconnected, here is my working snippet:

const channelWrapper = conn.createChannel({
  setup: async (ch: amqplib.ConfirmChannel) => {
    ch.on('error', (err) => {
      console.log(err)
    })
  }
})

you can handle it inside setup function, so channel exception will be handled in error handler

s60912frank avatar Dec 16 '22 06:12 s60912frank

I tried the above code but it only catches the error, the mq server is not responding anymore, i guess because it has not reconnected.

dsoyez avatar Jun 16 '23 16:06 dsoyez