6 Replies Latest reply on Jul 22, 2015 6:48 AM by jbertram

    Jms consumers concurrency

    lauradp

      Hi,

      I have two queues (queueA, queueB) and many instances of consumerA and consumerB listening on queueA and queueB respectively. All consumers share the same jms session.

      Suppose consumerA takes a long time for consuming a message (I mean that the onMessage method takes a long time to execute). If a message is published in queueB while consumerA is handling a message, consumerB does not process the message, even if it is not busy.

       

      Can anyone explain me this behavior and how to avoid it?

       

      Laura

        • 1. Re: Jms consumers concurrency
          jbertram

          JMS sessions are not thread-safe and should never be shared among concurrent threads.  Every consumer should get its own session.  However, all sessions can share the same connection.

          • 2. Re: Jms consumers concurrency
            lauradp

            I tried creating a new session for each consumer and no message is consumed at all.

             

            In Jms-metrics page I can see 10 consumers listening on the queue and 1 message in the queue (o in delivery).

            How can I get rid of this block?

             

            Laura

            • 3. Re: Jms consumers concurrency
              jbertram

              I assume the problem is due to a bug in your application so I can't help you more until you provide me with more details about what your application is doing specifically.

              • 4. Re: Jms consumers concurrency
                lauradp

                You were right, I was not starting the connection.

                 

                Can I use a consumer for each queue (I.e. all consumers listening on the same queue share the same session)?

                 

                Laura

                • 5. Re: Jms consumers concurrency
                  zzz_public

                  I think there may be another solution similar to network connection management.

                  Don't issue business login in an onMessage method but just receive a message and put it to some BlockingQueue. Then organaze a thread pool behind that queue. Workers in the thread pool could do business logic.

                  • 6. Re: Jms consumers concurrency
                    jbertram

                    I would steer clear of sharing sessions altogether.