<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
HornetQ message count.
</h3>
<span style="margin-bottom: 10px;">
created by <a href="http://community.jboss.org/people/rishi321">Rishi k</a> in <i>JBoss Web Development</i> - <a href="http://community.jboss.org/message/588957#588957">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><table><tbody><tr><td class="votecell" style=";"><p class="vote" style="min-height: 8pt; height: 8pt; padding: 0px;"> </p>    </td>   <td class="postcell" style=";">       <p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Hi all,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I am new to HOrnetQ, I need to get message count from HornetQ running on Jboss6Final.But it shows the following error:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Here is my code</p></td></tr></tbody></table><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><code>public static void main(String[] args){<br/>    Context lContext=null;<br/>    Connection Hconn=null;<br/>    ConnectionFactory Hconnection=null;<br/>    HornetQQueue q=null;<br/>    ObjectName on;<br/>    Hashtable ht = new Hashtable();<br/>    ht.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");<br/>    ht.put(Context.PROVIDER_URL, "xx.xx.xxx.xx");<br/>    ht.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");<br/>    try{<br/>        lContext = new InitialContext(ht);<br/>        Hconnection = (ConnectionFactory) lContext.lookup("ConnectionFactory");<br/>        q = (HornetQQueue) lContext.lookup("/queue/ExpiryQueue");<br/>        //System.out.println(q.getQueueName());<br/>        on = ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(q.getQueueName());<br/>        JMXServiceURL url = new JMXServiceURL("rmi", "xx.xx.xxx.xx", 1099, "/jndi/jmx");<br/>        JMXConnector cntor = JMXConnectorFactory.connect(url, ht);<br/>        MBeanServerConnection mbsc = cntor.getMBeanServerConnection();<br/>        JMSQueueControl queueControl = (JMSQueueControl)MBeanServerInvocationHandler.newProxyInstance(mbsc, on, JMSQueueControl.class, false);<br/>        String counters = queueControl.listMessageCounter();<br/>        //System.out.print(counters);<br/>        MessageCounterInfo messageCounter = MessageCounterInfo.fromJSON(counters);         <br/>        System.out.format("%s message(s) in the queue (since last sample: %s)\n",messageCounter.getDepth(),messageCounter.getDepthDelta());<br/>    } catch (Exception e) {<br/>        e.printStackTrace();<br/>    }<br/><br/>}<br/></code></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>What seems to be wrong ?</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/588957#588957">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss Web Development at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2112">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>