访问的Apache的ActiveMQ通过JMX抛出异常(Accessing Apache Activ

2019-08-19 20:30发布

我使用的是新鲜的ActiveMQ 5.8.0安装,在那里我有一个名为“测试”队列中的消息。 我也取代了ACTIVEMQ_SUNJMX线bin/activemq启用JMX:

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

然后,我通过下面的代码查询JMX:

    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();
    }

访问的MBean时抛出异常。

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的也显示出我的MBean,想法?

Answer 1:

该bean名称已更改的事实是记录在5.8.0上发布网页 。

所以,你的对象名应该是这样的形式:

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


Answer 2:

优秀的答案。 在这里,你有使用的例子: API文档

还有一些重要的改变,从5.7到5.8。 对JMX服务默认网址从云:

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

至:

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


Answer 3:

可爱的问题和答案也一样,我有一个很难配置了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 =假”

,以及相应的代码是真的为我工作的人。 谢谢 ! (我用的ActiveMQ 5.8)



文章来源: Accessing Apache ActiveMQ via JMX throws Exception