Announcement Announcement Module
Collapse
No announcement yet.
maxConcurrentConsumers > 1; Multiple processes to read messages from Queue. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • maxConcurrentConsumers > 1; Multiple processes to read messages from Queue.

    Hi,

    We want to process multiple messages from the QUEUE simultaneously so we plan to use properties "maxConcurrentConsumers" and set its value greater than 1 so that multiple threads are spawned and simultaneously many messages can be processed.

    1. When i will set "maxConcurrentConsumers" > 1; documentation says that it will spawn multiple threads. Will the thread safety be ensured by the spring framework or it has to be taken care of by the developer.
    Is it that i only need to make my onMessage method thread safe and part of synchronization and thread safety will be taken care of by spring framework?

    2. Is there any disadvantage of "maxConcurrentConsumers" > 1. Some extra precautions i need to take care when i make this property greater than 1? Why will a coder not use this property as 10 and use as 5. Will making this value large have a negative impact.

    3. I read in documentation that the number of processes spawned would be dependent upon the load of messages incoming. Is that correct?

    Any inputs on the above would be helpful.

    Thanks in anticipation,
    Navneet

  • #2
    Your on method needs to be thread safe (but not synchronized) from the standpoint that spring will give a reference to your message processing bean to each thread that is processing messages.

    This is no different than any other bean that you have spring create for you that needs to either be stateless or thread safe.


    Spring will dynamically increase/decrease the consumers on the queue according to load. If there are no messages, spring will reduce the pool to "concurrentConsumers". If messages start flooding in, spring will increase the pool to "maxConcurrentConsumers".

    There's not point in having 5 or 10 listeners spinning on a queue if there are no messages to process.

    Comment


    • #3
      thanks ... the above information was very useful.

      Comment


      • #4
        Originally posted by navneetnavneetin View Post
        ...

        2. Is there any disadvantage of "maxConcurrentConsumers" > 1. Some extra precautions i need to take care when i make this property greater than 1? ...
        You should be ready to correctly handle the following use case:
        1. Message msg1 is posted to the destination (e.g. an order);
        2. Cancel order is posted to the same destination just after the previous (msg2);
        3. JMS specification guarantees that you get the messages at the same order but if you have, for example, two consumers, there is a possible case that the first consumer gets msg1 and the second gets msg2 almost at the same time. There is a possibility that msg2 is processed before msg1 then (due to thread-scheduling, processing logic etc). Hence, you can't be sure that you process messages at particular order if you have more than one consumer;

        There are, as usual, benefits and drawbacks at every approach. If you have a single consumer, your processing logic is easier to implement, however, performance may hurt. If you have more than one consumer, jms processing speed is higher but you should take care about possible messages processing reordering, hence, the code is more complex. You should just weight pros and cons and select what suits you best.

        Comment


        • #5
          Thanks for the valuable input.

          Comment

          Working...
          X