[Other] Recommended number of connections when using multiple independent consumers (Camel + Spring-AMQP) #14990
-
Community Support Policy
RabbitMQ version used4.1.x How is RabbitMQ deployed?Community Docker image Steps to reproduce the behavior in questionHello, I have a question regarding RabbitMQ best practices for the number of client connections when using many independent consumers. In my application (Java / Spring Boot), I am using Apache Camel with the 'spring-rabbitmq' component, which internally uses Spring-AMQP. By default, Spring-AMQP gives all listener containers the same ConnectionFactory, and therefore all consumers share a single TCP connection and a single underlying executor thread pool (default size: availableProcessors * 2 threads) In our setup, several independent Camel routes (each consuming from its own queue with prefetch: 1 and manual ackn) start to block each other because they share the same ConnectionFactory and the same thread pool. This leads to consumer stops even though queues are independent. This happens in specific situations (network outage, connection problem with an external system) where the camel route may need some time to complete, which leeds to the mentioned blocking scenario. Current RabbitMQ infrastructure overview:
My questions:
Any guidance from RabbitMQ maintainers would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
A connection factory creates connections, so you can have a 1-1 connection-to-consumer mapping with the same connection factory. A connection factory has a shared executor used to dispatch messages to consumer. It uses it for each connection it creates, unless you create a connection with
I guess you are using defaults, they are reasonable for most applications, but you may have to tweak your setup.
It is perfectly fine to do this. I can't say it is "recommended" because it depends on the workload.
No.
It is a limited number of connections, it should be fine on most hardware, unless you run thousands of instances of this application.
Channels are more lightweight and they exist to multiplex a connection. I can't answer precisely to this question, it depends on the workload.
There is the official documentation. |
Beta Was this translation helpful? Give feedback.
-
We cannot really know how many connections or connections per channel your specific system would need. Avoid connection churn, channel churn, and make sure to read the above doc guides (or, in the case of the Networking guide, those two specific sections). |
Beta Was this translation helpful? Give feedback.
A connection factory creates connections, so you can have a 1-1 connection-to-consumer mapping with the same connection factory.
A connection factory has a shared executor used to dispatch messages to consumer. It uses it for each connection it creates, unless you create a connection with
ConnectionFactory#newConnection(ExecutorService). There is a default value for this shared executor, but you can set your own. So there's plenty of solution to tweak the dispatching.