简体   繁体   English

从ActiveMQ队列中获取消息而不会出列

[英]Fetch message from ActiveMQ queue without dequeueing

I am taking messages from ActiveMQ queue and running a Java application which can succeed or fail. 我从ActiveMQ队列中获取消息并运行可以成功或失败的Java应用程序。

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. 禁用消息的自动确认,然后在工作完成后手动调用message.acknowledge()。 If an exception is thrown and thus the message.acknowlege() is not called, AMQ will attempt to deliver the message again. 如果抛出异常并因此未调用message.acknowlege(),则AMQ将尝试再次传递消息。 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 . 另一种方法是使用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. 但是,这对于检查来说更有用,从你描述的语义来看,mbelow的答案似乎是正确的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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