Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concurrency value in JMS topic listener in Spring

I know Spring but I am a newbie in JMS and started reading the Spring JMS. From the Spring JMS doc Spring doc, I read the following

The number of concurrent sessions/consumers to start for each listener.
Can either be a simple number indicating the maximum number (e.g. "5") 
or a range indicating the lower as well as the upper limit (e.g. "3-5").  
Note that a specified minimum is just a hint and might be ignored at 
runtime. Default is 1; keep concurrency limited to 1 in case of a topic 
listener or if queue ordering is important; consider raising it for 
general queues.

Just want to understand why should the concurrency limited to 1 in case of a topic listener? If I increase it, say to 10 instead of 1, what would happen?

like image 812
Anand Avatar asked Sep 12 '25 04:09

Anand


1 Answers

Each subscriber receives a copy of each message published to a Topic. It makes no sense at all to put up multiple consumer, since all your application would do is to receive the same message 10 times, in different threads.

In the case of a Queue, messages on the queue would be distributed among 10 threads and hence, handled concurrently. That is indeed a very common scenario - load balancing.

like image 94
Petter Nordlander Avatar answered Sep 14 '25 23:09

Petter Nordlander