I'm trying to see difference between DirectMessageListener
and SimpleMessageListener
. I have this drawing just to ask if it is correct.
Let me try to describe how I understood it and maybe you tell me if it is correct.
In front of spring-rabbit
there is rabbit-client
java library, that is connecting to rabbit-mq server and delivering messages to spring-rabbit library. This client has some ThreadPoolExecutor
(which has in this case I think - 16 threads). So, it does not matter how many queues are there in rabbit - if there is a single connection, I get 16 threads. These same threads are reused if I use DirectMessageListener
- and this handler method listen
is executed in all of these 16 threads when messages arrive. So if I do something complex in handler, rabbit-client
must wait for thread to get free in order to get next message using this thread. Also if I increase setConsumersPerQueue
to lets say 20, It will create 20 consumer per queue, but not threads. These 20*5 consumers in my case will all reuse these 16 threads offered by ThreadPoolExecutor
?
SimpleMessageListener
on the other hand, would have its own threads. If concurrent consumers == 1 (I guess default as in my case) it has only one thread. Whenever there is a message on any of secondUseCase*
queues, rabbit-client
java library will use one of its 16 threads in my case, to forward message to single internal thread that I have in SimpleMessageListener
. As soon as it is forwarded, rabbit-client
java library thread is freed and it can go back fetching more messages from rabbit server.