4 Replies Latest reply on Nov 19, 2008 9:08 AM by Adrian Brock

    queue statistics

    marco baroetto Newbie

      Hello, I'm new into JMS and JBoss MQ. I wonder if it is possibile to access to a javax.jms.Queue statistics using jboss mq. I found the MessageCounter class into org.jboss.mq.server package but i don't know how to access it starting from a javax.jms.queue.

      What i want to do is to check the current number of message in the queue from code without using a QueueBrowser.
      Here is my code:

      Properties props = new Properties();
      QueueSession queueSession;
      QueueSender queueSender;
      props.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming.client" );
      props.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099");
      props.setProperty("j2ee.clientName", "MessageClient");
      Context ctx= new InitialContext(props);
      QueueConnectionFactory queueConnectionFactory =
      (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
      QueueConnection queueConnection =
      javax.jms.Queue queue = (javax.jms.Queue)ctx.lookup("queue/MyQueue");
      queueSession =
      (QueueSession)queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
      queueSender = queueSession.createSender(queue);

      thank you!

        • 1. Re: queue statistics
          marco baroetto Newbie

          i got it:

           ObjectName queueObjectName = ObjectName.getInstance(stringObjectName);
           org.jboss.mq.server.jmx.QueueMBean queueMBean =
           (org.jboss.mq.server.jmx.QueueMBean) MBeanServerInvocationHandler.newProxyInstance(
           System.out.println("-------- QUEUE STATISTICS "+i+" ---------");
           System.out.println("queue depth "+i+": " + queueMBean.getQueueDepth());
           System.out.println("in process "+i+": " + queueMBean.getInProcessMessageCount());
           System.out.println("scheduled "+i+": " + queueMBean.getScheduledMessageCount());
           System.out.println("retries "+i+": " + queueMBean.getRecoveryRetries());
           }catch (Exception e){
           System.out.println("cannot get depth of the queue: " + e.getMessage() );

          • 2. Re: queue statistics
            marco baroetto Newbie

            i forgot this:

            String domain = "jboss.mq.destination";
            String service = "service=Queue";
            String name = "name=MyQueue";
            String stringObjectName = domain + ":" + service + "," + name;
            MBeanServer server = MBeanServerLocator.locateJBoss();

            • 3. Re: queue statistics
              m k Newbie

              is it ok? I have such problem:

              java.lang.IllegalStateException: No 'jboss' MBeanServer found!
               at org.jboss.mx.util.MBeanServerLocator.locateJBoss(MBeanServerLocator.java:122)

              • 4. Re: queue statistics
                Adrian Brock Master

                If you are not in the same JVM then you need to lookup the MBeanServerConnection
                bound in jndi at jmx/rmi/RMIAdaptor