Reputation:
I am currently attempting to build a NodeJS web app that has a web and a worker process, and using AMQP to communicate between them. With my current setup, starting the application involves launching a script for the web process (server.js
) and another script for the worker process (worker.js
). Each of them include
a third file, amqp.js
which uses a start function that involves creating a connection, then creating a channel, then asserting queues.
However, in attempting to debug another issue, I came across this article which appears to show a different structure: a connection is created first, and then the two processes are launched, each creating a channel to that connection and asserting two queues.
Should I be creating a new connection for every worker, and is it possible for me to implement this in an environment where the web and the worker are separate and cannot otherwise communicate?
Upvotes: 1
Views: 131
Reputation: 3185
RabbitMQ connection is considered long-living. If your clients share memory they should share a connection. It is just a general advice. I'm not aware of any downsides if you have say, 10 connections for your application. If you have thousands of connections, it will probably affect performance and can make monitoring harder.
To directly answer your question:
If your worker
is independent and don't share memory with anything, you have no other choice but to create new RabbitMQ connection for it. Otherwise reuse the connection.
Upvotes: 1