I'm using a fresh ActiveMQ 5.10.0 installation, where I have a message in a queue called 'testing'. I also replaced the ACTIVEMQ_SUNJMX line in bin/activemq to enable JMX:
JMXServiceURL url1 = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://10.222.222.222:1099/jmxrmi");
JMXConnector jmxc = JMXConnectorFactory.connect(url1);
MBeanServerConnection conn = jmxc.getMBeanServerConnection( );
ObjectName activeMQ = new ObjectName("org.apache.activemq:type=Broker,brokerName=TOM,connector=clientConnectors,connectorName=openwire");
// ObjectName activeMQ = new ObjectName("org.apache.activemq:type=Broker,brokerName=TOM");
Set<ObjectName> brokers = conn.queryNames(activeMQ, null);
if (brokers.size( ) == 0) {
throw new IOException("No broker could be found in the JMX.");
}
System.out.println("brokers.size() = " + brokers.size());
for (int i = 0; i < brokers.size(); i++) {
System.out.println("brokers = " + brokers.toArray()[i]);
}
// ObjectName name = brokers.iterator().next();
// BrokerViewMBean mbean = MBeanServerInvocationHandler.newProxyInstance(conn, activeMQ, BrokerViewMBean.class, true);
ConnectionViewMBean mbean = MBeanServerInvocationHandler.newProxyInstance(conn, activeMQ, ConnectionViewMBean.class, true);
System.out.println(" mbean.getConsumers()\n = " + mbean.getConsumers()
);
The exception thrown is
java.lang.reflect.UndeclaredThrowableException
This is a different except than "Exception in thread "main" java.io.IOException: No broker could be found in the JMX."