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

How to receive exception when Amqp fails to connect?

Open javiertrancoso opened this issue 5 years ago • 2 comments

const amqp = require('amqp-connection-manager')

const {CONNECTION_URL} = require('./config/env')

class AmqpConnectionService {

  async openConnection() {
    this.connection = await amqp.connect([CONNECTION_URL])
    this.channelWrapper = await this.connection.createChannel({setup(channel) {}})

    await this.channelWrapper.waitForConnect()
  }

With this code when the CONNECTION_URL is a wrong URL then the code get stuck on the waitForConnect().

javiertrancoso avatar Oct 31 '19 09:10 javiertrancoso

FYI, at least judging by the types provided, neither amqp.connect, nor connection.createChannel return Promises, so using await is incorrect.

tstelzer avatar Mar 25 '20 16:03 tstelzer

Whenever a connection fails, you'll get a disconnect event even amqp-connection-manager is not currently connected to RabbitMQ.

But, amqp-connection-manager doesn't know the difference between trying to connect to a bad URL, and connecting to a broker that is currently down - either way ampq-connection-manager has to just keep retrying and hope it eventually works.

jwalton avatar Mar 25 '20 19:03 jwalton