Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 997
galusben Avatar asked Jan 17 '26 23:01

galusben


2 Answers

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.

like image 55
Derick Bailey Avatar answered Jan 19 '26 13:01

Derick Bailey


It will depends on the volumetry of messages you will have. If it really is huge, maybe 2 or 3 connections could do it, but one per application seems to be the best choice

like image 24
DamCx Avatar answered Jan 19 '26 14:01

DamCx



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!