1

I am trying to connect to RabbitMQ cluster using nodejs library amqplib

I cannot find any information on connection string. I am trying var

amqp_url = 
 ["amqp://admin:admin@172.26.126.248:5672/vhost_test","amqp://admin:admin@172.26.126.249:5672/vhost_test","amqp://admin:admin@172.26.126.250:5672/vhost_test"];

is there any other library supports cluster?

user557657
  • 856
  • 1
  • 12
  • 35
  • See examples of how to define the URL here: https://www.cloudamqp.com/docs/nodejs.html and here: https://youtu.be/9V8Fbbup-WQ?t=115 – jrhodin Jul 02 '21 at 14:59
  • @jrhodin I looked into that document already but I coudn't find anything on connection string for cluster of nodes. Sorry if I am missing something. I will look into video. – user557657 Jul 02 '21 at 15:09

1 Answers1

0

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.