How to read JMS messages without consuming them -

2019-06-19 18:33发布

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 .!!

标签: jms activemq
3条回答
疯言疯语
2楼-- · 2019-06-19 19:04

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楼-- · 2019-06-19 19:08

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.

查看更多
混吃等死
4楼-- · 2019-06-19 19:09

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

查看更多
登录 后发表回答