node-amqp-connection-manager
node-amqp-connection-manager copied to clipboard
How to receive exception when Amqp fails to connect?
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()
.
FYI, at least judging by the types provided, neither amqp.connect
, nor connection.createChannel
return Promises, so using await
is incorrect.
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.