Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call rabbitmq from nodejs

i have a code

enter image description here

i'm get an error when i try to connect to rabbitmq daemon from nodejs

enter image description here

when i run same code beyond docker then nodejs successfully connect to the server(rabbitmq deamon).

How can i connect from nodejs deamon to rabbitmq deamon?

docker-compose config: docker-compose-dev.yml

like image 514
kirsanv43 Avatar asked Jul 28 '26 22:07

kirsanv43


1 Answers

Here is the thing: If both node app and the rabbitmq run on separate docker containers, they rely on docker networking to reach each other, so node app looks for a rabbitmq instance in the same container, which isn't the case.

RabbitMQ contanier has the port 5672 exposed with a link, which can be reached over the name of the container (according to the standards of docker compose), which means all the exposed ports of that container are available at rabbitmq:. If you change

amqp.connect('amqp://localhost:5672');

into

amqp.connect('amqp://rabbitmq:5672');

You're all good.

like image 151
ardilgulez Avatar answered Jul 31 '26 14:07

ardilgulez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!