What version are you use ?
If you are using version 0.5.0
or earlier, you can use this configuration:
const hosts = [
'rabbitmq-node1:5672',
'rabbitmq-node2:5672',
'rabbitmq-node3:5672'
];
const connection = await amqp.connect({
port: 5672,
username: 'guest',
password: 'guest',
hosts: hosts, // specify the cluster nodes
heartbeat: 60 // send a health check every 60 seconds to check that the connection is still active
});
otherwise if it's a version higher than 0.5.0, I think amqplib doesn't take into account this ability to specify hosts anymore.
In fact, it should do
const amqp_uri = 'amqp://guest:guest@rabbitmq-node1:5672';
const connection = await amqp.connect(amqp_uri);
and behind it, RabbitMQ provides the other urls of the nodes during the connection.