« Return to Thread: JMS Queue Browsing Receiver

JMS Queue Browsing Receiver

by 0x6e6562 :: Rate this Message:

Reply to Author | View in Thread

I'm trying to create a JMS receiver that browses a queue in a controlling thread using the QueueBrowser interface and then when it finds something, for each message, it calls a worker thread to consume _a_ message with a non blocking call.

The idea is that the browsing thread can peek at the queue in a non-transactional session and if there is anything to consume, this can be farmed out to separate threads, thereby minimising the time any worker thread would idle when there is potentially work arrived in the queue but not yet farmed out.

I've included the source of the receiver and my stripped down mule-config.

BrowsingMessageReceiver.java
test-mule-config.xml

My problem is that the first enqueued message gets consumed correctly, but the second enqueued message cannot get consumed.

When dequeueing the second message, the call to this consumer's receiveNoWait() method returns null, although there _is_ a message in the queue.

This fact is backed up by the JMX queue browser and the fact that you can create a browser in the same session which allows you to peek at the message.

The logic then sets the rollBackOnly flag and returns.

This then just cycles, because the controlling thread can still see the same message on the queue and hence dispatches another worker thread.

I've tried this with the JMS and the XA transaction managers, to no avail.

The JMS provider is activemq 4.0.1, I haven't tried another provider yet.

I'm not too confident that my transaction handling is correct, as I don't feel that I quite mastered the mule transaction management yet.

What I find strange is the fact that it works for the first message, but then for no subsequent message.

Does anybody have ideas or things that I can try?

 « Return to Thread: JMS Queue Browsing Receiver