Count number of messages in a JMS queue

后端 未结 3 1044
一个人的身影
一个人的身影 2021-02-05 10:51

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?

Thanks.

3条回答
  •  鱼传尺愫
    2021-02-05 11:08

    Using JmsTemplate

    public int getMessageCount(String messageSelector)
    {
        return jmsTemplate.browseSelected(messageSelector, new BrowserCallback() {
            @Override
            public Integer doInJms(Session s, QueueBrowser qb) throws JMSException
            {
                return Collections.list(qb.getEnumeration()).size();
            }
        });
    }
    

提交回复
热议问题