Count number of messages in a JMS queue
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. 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(); } }); } sunleo This is how you can count No of Messages in a Queue public static void main(String[] args) throws Exception { // get the initial context InitialContext ctx = new