7
A
回答
6
这是你可以指望没有消息的队列中的
public static void main(String[] args) throws Exception
{
// get the initial context
InitialContext ctx = new InitialContext();
// lookup the queue object
Queue queue = (Queue) ctx.lookup("queue/queue0");
// lookup the queue connection factory
QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.
lookup("queue/connectionFactory");
// create a queue connection
QueueConnection queueConn = connFactory.createQueueConnection();
// create a queue session
QueueSession queueSession = queueConn.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
// create a queue browser
QueueBrowser queueBrowser = queueSession.createBrowser(queue);
// start the connection
queueConn.start();
// browse the messages
Enumeration e = queueBrowser.getEnumeration();
int numMsgs = 0;
// count number of messages
while (e.hasMoreElements()) {
Message message = (Message) e.nextElement();
numMsgs++;
}
System.out.println(queue + " has " + numMsgs + " messages");
// close the queue connection
queueConn.close();
}
+0
我实际上运行这个例子,由于某种原因,当我在队列上有5000条消息时,消息数显示为400 –
+0
How do you say队列中有5000条消息。 – sunleo
+0
我在我的ActiveMQ控制台 –
5
使用JmsTemplate的
public int getMessageCount(String messageSelector)
{
return jmsTemplate.browseSelected(messageSelector, new BrowserCallback<Integer>() {
@Override
public Integer doInJms(Session s, QueueBrowser qb) throws JMSException
{
return Collections.list(qb.getEnumeration()).size();
}
});
}
相关问题
- 1. JMS队列接收消息?
- 2. 替换jms队列中的消息
- 3. JMS队列中的延迟消息
- 4. 如何统计窗口消息队列中的消息?
- 5. WMI查询来统计MSMQ毒性队列中的消息数
- 6. Glassfish 3.1 JMS队列监测和统计
- 7. Java内部消息队列/ JMS
- 8. 发送XML消息给SONIC JMS队列
- 9. 在JMS队列上发布消息?
- 10. 在JMS队列上测试消息
- 11. JMS消息 - 与队列关联
- 12. JMS队列消息接收订单
- 13. 错误从JMS消息获取队列
- 14. JMS消息回滚到队列
- 15. JMS消息重新传递到队列
- 16. 消息队列系统
- 17. 系统V消息队列
- 18. 消息系统中的表对队列
- 19. 如何获取jms队列中待处理消息的数量
- 20. JMS统计主题域中未决消息的数量
- 21. 在JMS队列上计算消息时出现奇怪行为
- 22. JMS消息生产者不会将消息发送到队列
- 23. 消息队列设计
- 24. 使用多线程从JMS队列中消费消息
- 25. JMS - 消费者在消费之前浏览队列消息
- 26. JMS/Glassfish - 不消耗队列消息的MDB
- 27. JMS大桥现有的队列中的消息
- 28. 系统-V的消息队列PHP C++
- 29. 带jms的消息计数器Hornetq
- 30. 如何识别Spring Jms消息监听器中的消息队列名称
你可以在某些情况下使用JMX(取决于JMS实现的) – user1516873
我明白了,'的ActiveMQ '标签。 ActiveMQ的例子http://java.dzone.com/articles/managing-activemq-jmx-apis – user1516873