How to read JMS messages without consuming them - using ActiveMQ

房东的猫 提交于 2019-12-19 18:24:31

问题


I would like to know if there is any way to read a jms and actibemq messages without consuming it ?? I know messages can be consumed from the queue , yet still I want ask this question .!!


回答1:


You can browse Messages on a Queue via the JMS QueueBrowser, or in ActiveMQ you can browse the contents over JMX or with the commands line tools:

ActiveMQ console tools

JMS QueueBrowser API

ActiveMQ JMX




回答2:


Rather than using Message-consumers you need to use the QueueBrowser class for doing this:

ConnectionFactory connectionFactory = 
    new ActiveMQConnectionFactory("tcp://127.0.0.1:61616"); 
Connection connection = 
    connectionFactory.createConnection("admin","admin");
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("Test");
QueueBrowser queueBrowser = session.createBrowser(queue);
Enumeration msgs = queueBrowser.getEnumeration();
while (msgs.hasMoreElements()) {
    //do your things here
}



回答3:


Another option is to "consume" the messages but just in a transaction, then when you're done, roll it back, but a browser might be better since that's "what it's for" as it were.

If you're just looking for a particular message, and manual will do, you can see (I think all, at least some of) the messages and their contents for an activemq by clicking on the "RSS feed" button in the UI. which basically dumps them all to the screen. The "atom feed" option seems to load faster than the "RSS" one FWIW.



来源:https://stackoverflow.com/questions/14243966/how-to-read-jms-messages-without-consuming-them-using-activemq

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!