-
1. Re: Queue MessageCount - JMX Help
timfox May 23, 2007 5:13 PM (in response to kemplin)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
kemplin May 24, 2007 5:00 PM (in response to kemplin)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
timfox May 24, 2007 5:39 PM (in response to kemplin)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 likeserver.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 May 25, 2007 4:28 AM (in response to kemplin)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
timfox May 25, 2007 5:01 AM (in response to kemplin)Please take this discussion to the JMX users forum, or I will move it there myself.