1

I`m trying to look at the messages from a queue using a Browser. Code is like:

javax.naming.InitialContext ctx = new javax.naming.InitialContext();
javax.jms.QueueConnectionFactory qcf = (javax.jms.QueueConnectionFactory)ctx.lookup('java:/XAConnectionFactory');

javax.jms.QueueConnection connection = qcf.createQueueConnection('admin', 'admin'); // qcf.createQueueConnection();
javax.jms.QueueSession session = connection.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
connection.start();

// It is a "special" queue and it is not looked up from JNDI but constructed directly
javax.jms.Queue queue = (javax.jms.Queue)ctx.lookup('/queue/myQueue');

javax.jms.QueueBrowser browser = session.createBrowser(queue);

TreeMap<Date, javax.jms.Message> messageMap = new TreeMap<Date, javax.jms.Message>();
int counter = 0;

Enumeration<javax.jms.Message> enumeration = browser.getEnumeration();
while (enumeration.hasMoreElements()) {
  counter++;
  javax.jms.Message message = enumeration.nextElement();
  messageMap.put(new Date(message.getJMSTimestamp()), message);
}

connection.stop();
ctx.close();
session.close();
connection.close();

The problem is that I always get only 1 message in the enumeration, even though when looking with the jmx-console and invoke listMessagesAsJSON I get tons of messages.

Any ideas on what am I doing wrong ?

4

2 回答 2

1

在设置消费者窗口大小时(就像我在我的应用程序中所做的那样),您似乎可以遇到错误https://issues.jboss.org/browse/HORNETQ-691

于 2013-10-29T14:24:55.743 回答
1

正如 Sergiu 所说,您可能遇到了错误。

作为一种解决方法,您可以在连接工厂上以不同的方式定义使用者窗口大小。也许有一个专门针对这个用例的连接工厂……或者升级 HornetQ 的版本。

于 2013-10-29T14:48:17.023 回答