1
votes

I have been following RabbitMQ tutorials to add publisher and consumer to NodeJS. But the documentation and general tutorials on internet lacks to give proper production setup for using RabbitMQ client with Nodejs Cluster setup.

From RabbitMQ tutorial channel.consume() starts a consumer. Does this consumer starts in the same thread as Nodejs is running? If I run 4 Nodejs child processes that means it will created 4 consumers, right?

What would be the correct way of starting Nodejs app that only runs RabbitMQ workers by taking worker count from environment variable?

1

1 Answers

0
votes

From RabbitMQ tutorial channel.consume() starts a consumer. Does this consumer starts in the same thread as Nodejs is running?

Yes, consumers are also subject to the single-thread rule thus consuming synchronously can block your entire application.

If I run 4 Nodejs child processes that means it will created 4 consumers, right? Yes

What would be the correct way of starting Nodejs app that only runs RabbitMQ workers by taking worker count from environment variable?

I'm not sure what is the logic behind this, but I would strongly advise against arbitrarily limiting the number of consumers, quite the contrary. In order to keep your queues empty you'd usually want to use as much consuming power as you can.


If you still want to limit the number of RabbitMQ consumers regardless of how many available node processes, you'd have to write business logic involving communication between the master and it's child processes, which is not a trivial affair.