5 Replies Latest reply on May 25, 2007 5:01 AM by Tim Fox

    Queue MessageCount - JMX Help

    Philip Kemplin Newbie

      I am attempting to get access to a Queue via JMX so I can check to see the number of messages (MessageCount).

      I created the queue upon startup of JBoss by copying the default demo Queues in destinations-service.xml

      <mbean code="org.jboss.jms.server.destinatiosn.QueueService"
      name="jboss.messaging.destination:service=Queue,name=myqueue xmbean-dd="xmdesc/Queue-xmbean.xml">
      <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer
      jboss.message:service=PostOffice


      Inside my code I have the following:

      Properties props = new Propeties();
      props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      props.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      props.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099");
      
      InitialContext ctx = new InitialContext(props);
      
      Object o = ctx.lookup("jmx/rmi/RMIAdaptor");


      the object that is returned is a JRMPInvokerProxy, when I expected to get back an RMIAdaptor (as per all the examples I've seen).

      Does anyone know why I'm getting this class? I expected to get an RMIAdaptor.

      If I cast it as an RMIAdaptor and then invoke the method:

      rmiAdaptor.getAttribute("jboss.messaging.destination:service=Queue,name=myqueue", "MessageCount")
      

      I get an UnmarshalException....ClassNotFoundException org.jboss.jmx.connector.invoker.client.InvokerAdaptorException (no security manager: RMI class loader disabled).

      If someone can help, I'd really appreciate it. As you can tell, I'm new to JMX and trying to figure this out. If you have an example of getting the message count, I'd *really* appreciate it :-)


      In my classpath, I have jboss-messaging-client.jar.
      I'm using JBoss 4.0.5,
      messaging 1.2.0sp1,
      and JDK 6.


      thanks.

        • 1. Re: Queue MessageCount - JMX Help
          Tim Fox Master

          A two minute search of the wiki would have answered your question
          http://wiki.jboss.org/wiki/Wiki.jsp?page=HowDoIGetRemoteAccessToMyMBean.

          You're lucky I'm nice and Adrian isn't lurking ;)

          • 2. Re: Queue MessageCount - JMX Help
            Philip Kemplin Newbie

            Thanks for your response. I searched the forums prior to sending in my message, but didn't find the articles you pointed me to. I think I'm making progress, but am still coming up short.

            My applications are external to JBoss. I'm able to send/receive messages without any problem. However, my sender app wants to monitor the number of messages in the queue via JMX. From the links you pointed me to, I think my problem was mostly descriptor related. I now have:

            <mbean code="org.jboss.jms.server.destination.QueueService"
             name="jboss.messaging.destination:service=Queue,name=MyQueue"
             xmbean-dd="xmdesc/Queue-xmbean.xml">
             <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
             <depends>jboss.message:service=PostOffice</depends>
             ...snip security part guest read write
            </mbean>
            
            <mbean code="org.jboss.invocation.jrmp.server.JRMPProxyFactory"
             name="jboss.jmx:type=adaptor,name=MyQueueTarget,protocol=jrmp,service=proxyFactory">
             <depends optional-attribute-name="InvokerName">jboss:service=invoker,type=jrmp</depends>
             <depends optional-attribute-name="TargetName">
             jboss.messaging.destination:service=Queue,name=MyQueue
             </depends>
             <attribute name="JndiName">MyQueueMBean</attribute>
             <attribute name="InvokeTargetMethod">true</attribute>
             <attribute name="ExportedInterfaces">org.jboss.jms.server.destination.QueueMBean</attribute>
             <attribute name="ClientInterceptors">
             <interceptors>
             <interceptor>org.jboss.proxy.ClientMethodInterceptor</interceptor>
             <interceptor>org.jboss.proxy.SecurityInterceptor</interceptor>
             <interceptor>org.jboss.jmx.connector.invoker.client.InvokerAdaptorClientInterceptor</interceptor>
             <interceptor>org.jboss.invocation.InvokerInterceptor</interceptor>
             </interceptors>
             </attribute>
             </mbean>
            

            Inside my code, Its really simple:
            mBeanServer = (MBeanServerConnection) ctx.lookup("jmx/rmi/RMIAdaptor");
            org.jboss.jms.serer.destination.QueueMBean qmbean = (org.jboss.jms.server.destination.QueueMBean) ctx.lookup("MyQueueMBean");


            System.out.println(qmbean) --> JRMPInvokerProxy

            When I attempt to do a qmbean.getMessageCount() I get an IllegalStateException: Failed to find method for hash:..... and it then prints the methods available on a QueueMBean.

            I *have* searched the forum and this error seems to imply a jar related problem. I have ensured that my version of jboss-messaging-client.jar is one provided in messaging 1.2.0sp1. I have looked at the dates on the QueueMBean class within that jar, and they match the dates/size of the QueueMBean located in the jboss/server/messaging/deploy/jboss-messaging.sar/jboss-messaging.jar.

            One post I read at http://www.jboss.com/index.html?module=bb&op=viewtopic&t=92737 says that there was a problem with old JMX classes bundled in the jboss-messaging-client.jar. I removed those and it still doesn't work.

            The jboss-messaging-client.jar is the first jar in my classpath.

            At this point, I'm not sure where the incompatibility is. Any ideas?

            Thanks.

            • 3. Re: Queue MessageCount - JMX Help
              Tim Fox Master

              There is no incompatibility and this is nothing to with your descriptors.

              You are asking a basic JMX question - this is nothing to do with JBoss Messaging.

              I suggest what you really need to do is buy a book on JMX - this will tell you how to invoke methods and query attributes on an MBean.

              There are plenty of books on Amazon that will tell you how to do this

              [hint]
              You cannot just call qmbean.getMessageCount() to get the message count from an MBean - it is *not* a normal Java object.
              [/hint]

              To invoke an operation on an MBean you do something like

              server.invoke(new ObjectName("MyDomain:key=property"), "doSomething", new Object[0], new String[0]);
              


              There are similar operations to query attributes and do various other things.

              This was explained in the wiki page that I told you about in the last post.

              As I say, this is not the forum for me to explain the basics of JMX to you.

              Please buy a JMX book or as in the JMX forum.





              • 4. Re: Queue MessageCount - JMX Help
                mskonda Apprentice

                You can locate/create a Queue/TopicMBean by following method (from Kabutar):

                 private void initDestinationInfo(String destName, String type)
                 {
                
                 try
                 {
                
                 mBeanServer = JMXUtil.getMBeanServer(ContextUtil.getContext());
                
                 serverObjectName = new ObjectName(
                 "jboss.messaging.destination:service=" + type + ",name="
                 + destName);
                 if (type.equalsIgnoreCase(Destination.QUEUE))
                 {
                
                 queueMBean = (QueueMBean) MBeanServerInvocationHandler
                 .newProxyInstance(mBeanServer, serverObjectName,
                 QueueMBean.class, false);
                 setIsQueue(true);
                
                 } else if (type.equalsIgnoreCase(Destination.TOPIC))
                 {
                
                 topicMBean = (TopicMBean) MBeanServerInvocationHandler
                 .newProxyInstance(mBeanServer, serverObjectName,
                 TopicMBean.class, false);
                 setIsQueue(false);
                 }
                
                 } catch (NamingException e)
                 {
                 logger.warn("NamingException:" + e.getMessage());
                 logger.error(e);
                 } catch (Exception e)
                 {
                 logger.info("Exception:" + e.getMessage());
                 logger.error(e);
                 }
                 }
                


                Once you get the Queue/TopicMBean, all you have to do is to invoke approriate methods:
                qMBean.getMessageCount()
                qMBean.getConsumerCount()
                etc..
                


                You get the idea, didn't you?

                You can browse the above code in Kabutar:

                http://kabutar.googlecode.com/svn/trunk/src/com/agilyx/kabutar/browser/jms/


                Thanks
                Madhu


                • 5. Re: Queue MessageCount - JMX Help
                  Tim Fox Master

                  Please take this discussion to the JMX users forum, or I will move it there myself.