4 Replies Latest reply on Nov 19, 2008 9:08 AM by adrian.brock

    queue statistics

    marcobaroetto

      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.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
      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 =
      queueConnectionFactory.createQueueConnection();
      
      javax.jms.Queue queue = (javax.jms.Queue)ctx.lookup("queue/MyQueue");
      
      queueSession =
      (QueueSession)queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
      
      queueSender = queueSession.createSender(queue);
      
      queueSender.setDeliveryMode(DeliveryMode.PERSISTENT);


      thank you!

        • 1. Re: queue statistics
          marcobaroetto

          i got it:

          
          try{
           ObjectName queueObjectName = ObjectName.getInstance(stringObjectName);
          
           org.jboss.mq.server.jmx.QueueMBean queueMBean =
           (org.jboss.mq.server.jmx.QueueMBean) MBeanServerInvocationHandler.newProxyInstance(
           server,
           queueObjectName,
           org.jboss.mq.server.jmx.QueueMBean.class,
           false
           );
          
          
           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());
           System.out.println("---------------------------------------------------");
          
          
           }catch (Exception e){
           System.out.println("cannot get depth of the queue: " + e.getMessage() );
           }


          • 2. Re: queue statistics
            marcobaroetto

            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
              kulmar

              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

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