2 Replies Latest reply: Sep 23, 2010 7:20 AM by wgkorb RSS

    Multiple consumers of the same Queue

    wgkorb
      In the past my use of JMS queues has been limited to a single message producer and a single consumer. I am now looking at having multiple copies of the same consumer running for load balancing and failover purposes, and this leads me to what I think is a basic question. BTW, we're running OpenMQ 4.4u1.

      I have messages being produced and saved in a single queue.

      I then have a consumer program whose logic is something like this:

      1. Create session with no transaction and CLIENT_ACKNOWLEDGE.
      2. Receive message from queue.
      3. Do some processing with message. Repeat processing attempts multiple times, if needed, until successful.
      4. Once processing is successful, acknowledge message.

      Assume that I am running multiple copies of the consumer in separate JVMs (or on separate servers, for that matter).

      Here are my related questions.

      1. If step 3 takes a long time (e.g., several minutes) can I be sure that only one instance of the consumer will receive the message?
      2. If a consumer is in step 3 and a catastrophic failure occurs (e.g., the JVM or server it is running on crashes) the message will never be acknowledged, but the session will not be shut down in an orderly fashion, either. Will the message that was received but never acknowledged eventually be delivered to another copy of the consumer?
      3. If step three takes a very long time (hours or days, rather than minutes), will the broker misinterpret this as a failure of the consumer and deliver the same message to another one of the consumers?

      Thank you for reading and/or responding to this question.

      Bill
        • 1. Re: Multiple consumers of the same Queue
          807581
          1. If step 3 takes a long time (e.g., several minutes) can I be sure that only one instance of the consumer will receive the message?
          A queue message will only be delivered and consumed by 1 consumer.
          2. If a consumer is in step 3 and a catastrophic failure occurs (e.g., the JVM or server it is running on crashes) the message will never be acknowledged, but the session will not be shut down in an orderly fashion, either. Will the message that was received but never acknowledged eventually be delivered to another copy of the consumer?
          Yes.
          3. If step three takes a very long time (hours or days, rather than minutes), will the broker misinterpret this as a failure of the consumer and deliver the same message to another one of the consumers?
          No, as long as the consumer's Session or Connection are intact
          • 2. Re: Multiple consumers of the same Queue
            wgkorb
            Excellent, thanks for your reply. One follow-up question.

            If the connection drops (e.g., I trip over the network cable) I assume that will generate a JMSException on the client side and/or close the session, and that the client will then need to deal with that situation?

            Thanks!
            Bill