1 Reply Latest reply on Feb 10, 2011 11:43 AM by Clebert Suconic

    getting QueuDepth with optimised core API

    skyde Newbie

      What is the right (fastest) way to get the number of message in the queue ?

       

          public int size(){

              ClientSession session;

              try {

                  session = sf.createSession(false, false, false);

                  ClientRequestor requestor = new ClientRequestor(session, "hornetq.management");

                  ClientMessage m = session.createMessage(false);

                  ManagementHelper.putAttribute(m, "core.queue." + queueName, "messageCount");

                  ClientMessage reply = requestor.request(m);

                  int count = (Integer) ManagementHelper.getResult(reply);

                  return count;

              } catch (Exception e) {

                  e.printStackTrace();

              }

              return 0;

          }

       

      or

       

          public synchronized int size(){

              ClientSession coreSession = null;

              int count = 0;

              try {

                  coreSession = sf.createSession(false, false, false);

                  ClientSession.QueueQuery result;

                  result = coreSession.queueQuery(new SimpleString(queueName));

                  count = result.getMessageCount();

              } catch (HornetQException e) {

                  e.printStackTrace();

              } finally {

                  if (coreSession!= null ){

                      try {

                          coreSession.close();

                      } catch (HornetQException e) {

                          e.printStackTrace();

                      }

                  }

              }

              return count;

          }