Is it possible to have JMS queue wait until it has received the acknowledgement of a message before dispatching the next message

1.7k Views Asked by At

I have setup a JMS queue that is fed by a single producer, and consumed by 8 different consumers.

I would like to configure my queue/broker so that one message being delivered to a consumer blocks the queue until the consumer is done processing the message. During the processing of this first message, the following messages may not be delivered to another consumer. It doesn't matter which consumer processes which message, and it is acceptable for the same consumer to consume many messages in a row as long as when it dies another consumer is able to pick up the rest of the unprocessed messages.

In order to do this, I have configured all of my consumers to use the CLIENT acknowledgement mode, and I have coded them so that message.acknowledge() is called only at the end of the message processing.

My understanding was that this should be sufficient to satisfy my requirements.

However I am apparently wrong, because it looks like my brojer (OpenMQ) is delivering the messages to consumers as fast as possible, without waiting for the consumer acknowledgement. As a result, I get multiple messages processed in parallel, one for each consumer.

I'm obviously doing something wrong, but I can't figure out what.

As a workaround, I figure I could create a durable subscription with a fixed client ID shared between all my consumers. It would probably work by only allowing one consumer to even connect to the broker, but I can't shake the feeling that this is a rather ugly workaround.

Does anyone have an idea of how I should configure my Broker and/or my Client to make this possible?

0

There are 0 best solutions below