Search code examples
spring-amqp

Understanding DirectMessageListener concurrency


From Spring AMQP reference documentation,

With the DirectMessageListenerContainer, you need to ensure that the connection factory is configured with a task executor that had sufficient threads to support your desired concurrency across all listener containers that use that factory. The default pool size is only five.

However, there are some limitations with this approach, and certain features of the SMLC are not available with the DMLC. Also, concurrency is controlled by "consumersPerQueue" (and the client library’s thread pool).

  1. Let's say that I have configured a CachingConnectionFactory (associated with DirectMessageListenerContainer) with a custom Executor, with a thread pool size of 20.

    ExecutorService fixedPool = Executors.newFixedThreadPool(20);

    And,

    The client library's thread pool is set to ( 4 * 2 = 8), i.e. No of CPU cores = 4

    And,

    I have configured "consumersPerQueue=30" concurrency setting for my RabbitListener

I am a bit confused about exactly how many concurrent consumers will be processing messages from the queue?

A bit of guidance on how these settings compliment/override each other would be really helpful?


Solution

  • There is a discussion about the various executors used in the amqp-client library on the rabbitmq-users google group here.

    I am not sure which executor you are talking about "client library's thread pool" but, specifically, the caching connection factory executor service is passed in and used to invoke the consumers. Since it only has 20 threads, that is the maximum concurrency you will achieve.