4 Replies Latest reply on Oct 29, 2013 10:23 AM by Sergiu Pienar

    HornetQ browser

    Sergiu Pienar Expert

      I`m trying to look at the messages from a queue using a Browser.

      Code is like:


      javax.naming.InitialContext ctx = new javax.naming.InitialContext();

      javax.jms.QueueConnectionFactory qcf = (javax.jms.QueueConnectionFactory)ctx.lookup('java:/XAConnectionFactory');


      javax.jms.QueueConnection connection = qcf.createQueueConnection('admin', 'admin'); // qcf.createQueueConnection();

      javax.jms.QueueSession session = connection.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);



      // It is a "special" queue and it is not looked up from JNDI but constructed directly

      javax.jms.Queue queue = (javax.jms.Queue)ctx.lookup('/queue/myQueue');


      javax.jms.QueueBrowser browser = session.createBrowser(queue);


      TreeMap<Date, javax.jms.Message> messageMap = new TreeMap<Date, javax.jms.Message>();

      int counter = 0;


      Enumeration<javax.jms.Message> enumeration = browser.getEnumeration();

      while (enumeration.hasMoreElements()) {


        javax.jms.Message message = enumeration.nextElement();

        messageMap.put(new Date(message.getJMSTimestamp()), message);








      The problem is that I always get only 1 message in the enumeration, even though when looking with the jmx-console and invoke listMessagesAsJSON I get tons of messages.


      Any ideas on what am I doing wrong ?