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

    HornetQ browser

    sergiu_pienar

      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);

      connection.start();

       

      // 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()) {

        counter++;

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

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

      }

       

      connection.stop();

      ctx.close();

      session.close();

      connection.close();

       

      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 ?