amitabh pandey
amitabh pandey

Reputation: 75

How setConcurrency method works in Spring JMS

I am using ActiveMQ with Spring Boot. I have read about the setConcurrency method of Spring JMS. As per my understanding if we set 2 (this is the max limit) then two concurrent consumers will be created for a listener (assuming I have only one listener/consumer) on load basic on queue. Now I want to understand how it divide the load and on which basic. On how many messages on the queue will it create the 2 consumers?

Also in case of queue will one message delivered to exactly one consumer?

And do we need to ensure the thread safety in our code while setting the concurrency?

Upvotes: 0

Views: 2716

Answers (1)

Doug Grove
Doug Grove

Reputation: 1045

Let me try to answer your question(s). If you set the concurrency to 2, then you will have 2 JMS listeners (each on a different thread) on the single JMS connection/session that is managed by the Spring listener container.

These two listeners will look like any other 2 message consumers to your JMS message broker. Messages will be delivered to only one listener/consumer. In general, you should not need to worry about thread safety with multiple listeners. Obviously, it is certainly possible to write non-thread safe message handling application code (2 threads updating some application level data structures at the same time), but the Spring JMS code is thread-safe.

Upvotes: 2

Related Questions