I have a multithreaded application where one thread writes messages to a queue, and another thread accesses these messages via a QueueBrowser. The thread run simultaneously.
The second thread wants JMS to hold onto the messages until it is done with individual messages, so it uses QueueBrowser.getEnumeration() to get an enumeration, and then steps through the messages. Each message is added to a HashMap along with a Boolean that indicates whether the app is done with it (has logically released it).
Because the JMS spec says that acknowledging any message automatically acknowledges all messages received previous to the acknowledged messages, the app can't directly receive and acknowledge messages in order, as it may not be done with some of them. Whenever we update the HashMap, we look through the message entries in order starting with the oldest, and do a receive/acknowledge for each logically released message until we find one which has not been logically released. Basically, we only receive/acknowledge a message if we know that we are done with all the previous messages.
Obviously, this relies on the enumeration returned by QueueBrowser being accurate. But I get repeated results where the QueueBrowser enumerations do not include messages which have been sent to the queue. In each case, one or more messages are missing from the start of the set (i. e. the earliest messages). It is never the case that the latest messages are missing, so this can't be a case where the first thread's send() hadn't completed at the time the enumeration was constructed.
The release logic checks to see whether receive() gives it the JMS message ID it expects, based on the value saved in the HashMap entry, and I'm finding that the messages that were excluded from the enumeration show up in the proper order when receive() is issued.
If I run the sending thread by itself, and then run the receiving thread by itself when the sending thread has ended, all works as expected and no messages are lost.
I've verified this problem with both EAP 6.3 and an old pre-HornetQ JBossAS 5.1.0.
Am I misunderstanding how QueueBrowser is supposed to work ?