Count number of messages in a JMS queue

后端 未结 3 1049
一个人的身影
一个人的身影 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:34

    Java 8 & Spring Boot

       public int countPendingMessages(String destination) {
        // to an Integer because the response of .browse may be null
        Integer totalPendingMessages = this.jmsTemplate.browse(destination, (session, browser) -> Collections.list(browser.getEnumeration()).size());
    
        return totalPendingMessages == null ? 0 : totalPendingMessages;
       }
    

提交回复
热议问题