简体   繁体   中英

Fetch message from ActiveMQ queue without dequeueing

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM