<!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;">&#160;</p>&#160;&#160;&#160; </td>&#160;&#160; <td class="postcell" style=";">&#160;&#160;&#160;&#160;&#160;&#160; <p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Hi all,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</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;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</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:&#160; java.naming.factory.initial&#160;&#160;&#160; at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:338)&#160;&#160;&#160; at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)&#160;&#160;&#160; 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:&#160; java.naming.factory.initial&#160;&#160;&#160; at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)&#160;&#160;&#160; at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)&#160;&#160;&#160; at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)&#160;&#160;&#160; at javax.naming.InitialContext.lookup(InitialContext.java:392)&#160;&#160;&#160; at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1886)&#160;&#160;&#160; at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1856)&#160;&#160;&#160; at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:257)&#160;&#160;&#160; ... 2 more</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Here is my code</p></td></tr></tbody></table><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><code>public static void main(String[] args){<br/>&#160;&#160;&#160; Context lContext=null;<br/>&#160;&#160;&#160; Connection Hconn=null;<br/>&#160;&#160;&#160; ConnectionFactory Hconnection=null;<br/>&#160;&#160;&#160; HornetQQueue q=null;<br/>&#160;&#160;&#160; ObjectName on;<br/>&#160;&#160;&#160; Hashtable ht = new Hashtable();<br/>&#160;&#160;&#160; ht.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");<br/>&#160;&#160;&#160; ht.put(Context.PROVIDER_URL, "xx.xx.xxx.xx");<br/>&#160;&#160;&#160; ht.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");<br/>&#160;&#160;&#160; try{<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; lContext = new InitialContext(ht);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Hconnection = (ConnectionFactory) lContext.lookup("ConnectionFactory");<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; q = (HornetQQueue) lContext.lookup("/queue/ExpiryQueue");<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; //System.out.println(q.getQueueName());<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; on = ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(q.getQueueName());<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; JMXServiceURL url = new JMXServiceURL("rmi", "xx.xx.xxx.xx", 1099, "/jndi/jmx");<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; JMXConnector cntor = JMXConnectorFactory.connect(url, ht);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; MBeanServerConnection mbsc = cntor.getMBeanServerConnection();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; JMSQueueControl queueControl = (JMSQueueControl)MBeanServerInvocationHandler.newProxyInstance(mbsc, on, JMSQueueControl.class, false);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; String counters = queueControl.listMessageCounter();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; //System.out.print(counters);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; MessageCounterInfo messageCounter = MessageCounterInfo.fromJSON(counters);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.format("%s message(s) in the queue (since last sample: %s)\n",messageCounter.getDepth(),messageCounter.getDepthDelta());<br/>&#160;&#160;&#160; } catch (Exception e) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.printStackTrace();<br/>&#160;&#160;&#160; }<br/><br/>}<br/></code></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</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>