【问题标题】:Accessing Apache ActiveMQ via JMX throws Exception通过 JMX 访问 Apache ActiveMQ 抛出异常
【发布时间】:2013-03-28 02:24:18
【问题描述】:

我正在使用全新的 ActiveMQ 5.8.0 安装,其中我在名为“测试”的队列中有一条消息。我还替换了bin/activemq 中的 ACTIVEMQ_SUNJMX 行以启用 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,想法?

【问题讨论】:

    标签: exception activemq jmx


    【解决方案1】:

    问题和答案也很有趣,我在配置 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=false -Dcom.sun.management.jmxremote.ssl=false"

    ,相应的代码才是真正适合我的代码。谢谢 ! (我使用的是 ActiveMQ 5.8)

    【讨论】:

      【解决方案2】:

      很好的答案。这里有一个使用示例:API Docs

      从 5.7 到 5.8 还有一些重要的变化。 JMX 服务的默认 URL 来自:

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

      到:

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

      【讨论】:

        【解决方案3】:

        bean 名称已更改的事实记录在 5.8.0 release page 中。

        所以你的 ObjectName 应该是这样的形式:

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

        【讨论】:

        • 是的,这是正确的答案。不幸的是,我发现的所有示例都是 5.8 之前的版本
        • 蒂姆,如何修复被此破坏的工具的答案是什么 - 例如我无法使用 5.8.0 的 HermesJMS 和 ActiveMQBrowser?请帮忙!谢谢!
        • 有效,但我需要使用这个 ObjectName:org.apache.activemq:BrokerName=localhost,Type=Broker
        猜你喜欢
        • 2018-01-20
        • 2023-04-04
        • 1970-01-01
        • 1970-01-01
        • 2021-05-12
        • 1970-01-01
        • 2019-07-29
        • 1970-01-01
        • 2017-09-30
        相关资源
        最近更新 更多