gba gba - 4 months ago 31
Java Question

How many connections to maintain in RabbitMQ?

I am using the RabbitMQ java client.
My app has multiple exchanges and queues. Adopting something similar to the Pub/Sub model.

What is the best practice regarding connections?
Shall I have one connection per app?

I understand the channel model, and the thread (un)safety model. Just not sure if I should have multiple connections or not.


One connection per app is correct.

Within that connection, you will have many channels - where the actual work is done.

You can have hundreds or thousands of message producers and consumers (each on their on channel) inside a single connection.

If you start to see slowdown in your RMQ setup because you're dong too much work, look at clustering RMQ and/or standing up multiple instances of your app.

But you would still maintain 1 connection per app instance.