计算JMS队列中的消息数 [英] Count number of messages in a JMS queue

查看:150
本文介绍了计算JMS队列中的消息数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看JMS队列并获取其中的所有消息的最佳方法是什么?

What is the best way to go over a JMS queue and get all the messages in it?

如何计算队列中的消息数?

How can count the number of messages in a queue?

谢谢。

推荐答案

使用JmsTemplate

Using 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();
        }
    });
}

这篇关于计算JMS队列中的消息数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆