I have created a producer with transaction false
and CLIENT_ACKNOWLEDGE
that put 99 messages on the queue.
I created a consumer for the same queue with a different session and transacted false
and CLIENT_ACKNOWLEDGE
.
I did not acknowledge the first message and acknowledged the remaining 98 messages.
When I looked at the queue I expected to see 1 message pending / 1 on queue, but to my surprise I see all 99 messages dequeued.
Can someone please point out where I went wrong?
You're seeing the expected behavior as dictated by the JMS specification. Section 4.4.11 titled "Message Acknowledgment" of the JMS 1.1 spec states:
CLIENT_ACKNOWLEDGE - With this option, a client acknowledges a message by calling the message’s
acknowledge
method. Acknowledging a consumed message automatically acknowledges the receipt of all messages that have been delivered by its session. [emphasis added]
Some JMS brokers offer extended acknowledge modes (e.g. ActiveMQ Artemis and ActiveMQ "Classic") which may be helpful in this situation.