1 Reply Latest reply on Feb 22, 2011 4:16 PM by clebert.suconic

    HornetQ message count ?

    rishi321

      Hi all,

       

      I am new to HOrnetQ, I need to get message count from HornetQ running on Jboss6Final.But it shows the following error:

       

       

      ExpiryQueuejava.io.IOException: Failed to retrieve RMIServer stub: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:338)    at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)    at com.jboss.embedded.TestNG.TestCounters.main(TestCounters.java:51)Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)    at javax.naming.InitialContext.lookup(InitialContext.java:392)    at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1886)    at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1856)    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:257)    ... 2 more

       

       

      Here is my code:

       

      public static void main(String[] args){
          Context lContext=null;
          Connection Hconn=null;
          ConnectionFactory Hconnection=null;
          HornetQQueue q=null;
          ObjectName on;
          Hashtable ht = new Hashtable();
          ht.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
          ht.put(Context.PROVIDER_URL, "xx.xx.xxx.xx");
          ht.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
          try{
              lContext = new InitialContext(ht);
              Hconnection = (ConnectionFactory) lContext.lookup("ConnectionFactory");
              q = (HornetQQueue) lContext.lookup("/queue/ExpiryQueue");
              //System.out.println(q.getQueueName());
              on = ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(q.getQueueName());
              JMXServiceURL url = new JMXServiceURL("rmi", "xx.xx.xxx.xx", 1099, "/jndi/jmx");
              JMXConnector cntor = JMXConnectorFactory.connect(url, ht);
              MBeanServerConnection mbsc = cntor.getMBeanServerConnection();
              JMSQueueControl queueControl = (JMSQueueControl)MBeanServerInvocationHandler.newProxyInstance(mbsc, on, JMSQueueControl.class, false);
              String counters = queueControl.listMessageCounter();
              //System.out.print(counters);
              MessageCounterInfo messageCounter = MessageCounterInfo.fromJSON(counters);        
              System.out.format("%s message(s) in the queue (since last sample: %s)\n",messageCounter.getDepth(),messageCounter.getDepthDelta());
          } catch (Exception e) {
              e.printStackTrace();
          }

      }

       

      What seems to be wrong?

        • 1. HornetQ message count ?
          clebert.suconic

          You have to specify the jndi.properties file in your classpath (I don't remember the exact name now), or the hashmap properties for your JNDI server.

           

           

          Take a look on the 100+ examples on HornetQ. Most of them are doing that.