2013-04-05 71 views
1

我正在使用新鮮的ActiveMQ 5.8.0安裝,其中我在一個名爲'testing'的隊列中有一條消息。我還更換了ACTIVEMQ_SUNJMX線bin/activemq啓用JMX:通過JMX訪問Apache ActiveMQ拋出異常

ACTIVEMQ_SUNJMX_START="-Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false" 

然後我通過下面的代碼查詢JMX:訪問所述的mbean時

try { 
     JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi")); 
     connector.connect(); 
     MBeanServerConnection connection = connector.getMBeanServerConnection(); 

     ObjectName mbeanName = new ObjectName("org.apache.activemq:BrokerName=localhost,Type=Broker"); 
     BrokerViewMBean mbean = MBeanServerInvocationHandler.newProxyInstance(connection, mbeanName, BrokerViewMBean.class, true); 

     System.out.println("Id:" + mbean.getBrokerId()); // here the exception will be thrown 
    } 
    catch (Exception x) { 
     x.printStackTrace(); 
    } 

拋出異常。

java.lang.reflect.UndeclaredThrowableException 
    at $Proxy0.getBrokerId(Unknown Source) 
    at testing.TestJmx.main(TestJmx.java:25) 
Caused by: javax.management.InstanceNotFoundException: org.apache.activemq:BrokerName=localhost,Type=Broker 
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1095) 
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:643) 
    at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:668) 
    at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1424) 
    at javax.management.remote.rmi.RMIConnectionImpl.access$200(RMIConnectionImpl.java:89) 
    at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1292) 
    at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1380) 
    at javax.management.remote.rmi.RMIConnectionImpl.getAttribute(RMIConnectionImpl.java:621) 
    at sun.reflect.GeneratedMethodAccessor30.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:601) 
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322) 
    at sun.rmi.transport.Transport$1.run(Transport.java:177) 
    at sun.rmi.transport.Transport$1.run(Transport.java:174) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at sun.rmi.transport.Transport.serviceCall(Transport.java:173) 
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553) 
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808) 
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) 
    at java.lang.Thread.run(Thread.java:722) 
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273) 
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251) 
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:160) 
    at com.sun.jmx.remote.internal.PRef.invoke(Unknown Source) 
    at javax.management.remote.rmi.RMIConnectionImpl_Stub.getAttribute(Unknown Source) 
    at javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection.getAttribute(RMIConnector.java:901) 
    at javax.management.MBeanServerInvocationHandler.invoke(MBeanServerInvocationHandler.java:280) 
    ... 2 more 

我檢查了那個端口正在偵聽,VisualVM也顯示了我的mbeans,想法?

回答

8

5.8.0 release page中記錄了bean名稱已更改的事實。

所以,你的對象名應該是這樣的形式:

ObjectName mbeanName = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost"); 
+1

是的,這是正確的答案。不幸的是,我發現的所有例子都有5.8版本的發行版 – Dag 2013-04-05 20:44:30

+1

Tim,那麼如何解決由此破解的工具 - 比如HermesJMS和ActiveMQBrowser,我無法使用5.8.0? 請幫忙! 謝謝! – 2013-05-16 08:52:52

+0

@OlegKiorsak你有沒有得到它與HermesJMS – Franklin 2014-11-12 05:07:05

1

出色答卷。在這裏你有一個使用的例子:API Docs

還有一些重要的變化從5.7到5.8。爲JMX服務的默認網址雲來源:

service:jmx:rmi://localhost/jndi/rmi://localhost:1099/jmxrmi 

到:

service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi 
0

可愛的問題和答案也一樣,我有一個很難配置了JMX。 ActiveMQ文檔在這方面不是最新的。例如:http://activemq.apache.org/jmx.html不會從5.8.0開始說「SUNJMX」變成「ACTIVEMQ_SUNJMX_START」。

由OP提供的配置,即: ACTIVEMQ_SUNJMX_START =「 - Dcom.sun.management.jmxremote.port = 1099 -Dcom.sun.management.jmxremote.authenticate =假-Dcom.sun.management.jmxremote.ssl = false「

,相應的代碼是真正爲我工作的代碼。謝謝 ! (我正在使用ActiveMQ 5.8)