4
votes

I am taking messages from ActiveMQ queue and running a Java application which can succeed or fail.

In case the application fails, i want the message to remain on the queue, that is to keep it without dequeueing it.

Is there a way to take a message with out automaticly erasing it from the queue?

Is there are atom operation like fetching from queue or erasing from queue?

Thanks.

2

2 Answers

7
votes

Disable auto-acknowledge of messages, and then call message.acknowledge() manually after the work is done. If an exception is thrown and thus the message.acknowlege() is not called, AMQ will attempt to deliver the message again. If all attempts fail, the message is finally placed in the dead letter queue. This behavior can be configured.

2
votes

Another way is to use a QueueBrowser. This allow you to "look at messages on a queue without removing them". However, this is more useful for inspection purposes, from the semantics you described, mbelow's answer seems to be the right choice.