Calling Qpid JMX from ear deployed in JBoss7.1.2Final
gte338m Oct 19, 2012 10:38 AMAll
I have a Java Qpid Broker running on the same machine as JBoss7.1.2.Final. And am attempting to call JMX running in Qpid from an ear running in JBoss.
The following code when ran in a main method runs as expected. However, when I put the code inside an ear and call it via a webservice endpoint, I get the exception below. Appears that jboss is interpreting the url as if the code is attempting to connect to the jboss service. I was thinking that because qpid is listening on port 8999, that jboss would hit that port, there by triggering the jmx lookup on qpid.
Exception:
Failed to retrieve RMIServer stub: javax.naming.NameNotFoundException: rmi://localhost:8999/jmxrmi -- service jboss.naming.context.java.rmi:.localhost:8999.jmxrmi"}
Code:
String[] attributes = new String[]{"Name", "Owner", "ActiveConsumerCount", "AutoDelete", "Capacity", "ConsumerCount", "Description", "Durable", "Exclusive", "FlowOverfull",
"FlowResumeCapacity", "MaximumDeliveryCount", "MaximumMessageAge", "MaximumMessageCount", "MaximumMessageSize", "MaximumQueueDepth", "MessageCount", "QueueDepth", "QueueType", "ReceivedMessageCount"};
try {
Map<String, Object> environment = new HashMap<String, Object>();
// credentials: user name and password
environment.put(JMXConnector.CREDENTIALS, new String[]{"admin", "admin"});
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:8999/jmxrmi");
JMXConnector jmxConnector = JMXConnectorFactory.connect(url, environment);
MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection();
String[] domains = mbsc.getDomains();
for (int k = 0; k < domains.length; k++) {
String domain = domains[k];
ObjectName queueObjectName = new ObjectName(domain + ":*");
Set nameSet = mbsc.queryNames(queueObjectName, null);
Iterator it = nameSet.iterator();
while (it.hasNext()) {
ObjectName n = (ObjectName) it.next();
//System.out.println(n.getCanonicalName() + ": " + n.getKeyPropertyListString());
ObjectName queueObjectName2 = new ObjectName(domain+":"+n.getKeyPropertyListString());
Iterator it2 = mbsc.getAttributes(queueObjectName2, attributes).asList().iterator();
System.out.println("########################NEXT DOMAIN: "+domain+":"+n.getKeyPropertyListString());
while (it2.hasNext()) {
Attribute att = (Attribute) it2.next();
System.out.println("attribute: "+att.getName() + " value: " + att.getValue());
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Thanks