ActiveMQ监控队列状态报javax.management.InstanceNotFoundException

发布于 2021-11-17 20:38:03 字数 4519 浏览 714 评论 1

private static String brokerURI="tcp://localhost:12345";
    public static int connectorPort = 1099;
    public static String connectorPath = "/jmxrmi";
 
    BrokerService  broker=new BrokerService();
    broker.addConnector(brokerURI);
    broker.setPersistent(true);
    broker.setUseJmx(true);
 
    ManagementContext context = broker.getManagementContext();
    context.setConnectorPort(connectorPort);
    context.setConnectorPath(connectorPath);
 
    context.setCreateConnector(true);
    context.setCreateMBeanServer(true);
    broker.start();
 
    System.out.println(broker.getBrokerName());      // localhost
    System.out.println(context.getJmxDomainName());  //org.apache.activemq
 
   JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + connectorPort + connectorPath);
 
    JMXConnector connector = JMXConnectorFactory.connect(url, null);
    MBeanServerConnection connection = connector.getMBeanServerConnection();
     ObjectName name = new ObjectName("org.apache.activemq:BrokerName=localhost,Type=Broker");
 
     BrokerViewMBean mBean = (BrokerViewMBean) MBeanServerInvocationHandler.newProxyInstance(connection, name, BrokerViewMBean.class, true);
     System.out.println(mBean.getBrokerName());







 调用到mBean.getBrokerName()时会报异常:
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:678)
    at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1464)
    at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:97)
    at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1328)
    at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1420)
    at javax.management.remote.rmi.RMIConnectionImpl.getAttribute(RMIConnectionImpl.java:657)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    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:556)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:275)
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:252)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:161)
    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:913)
    at javax.management.MBeanServerInvocationHandler.invoke(MBeanServerInvocationHandler.java:267)
ObjectName的确是"org.apache.activemq:BrokerName=localhost,Type=Broker",应该没有错误。为何会提示实例不存在呢。。。。。。。。
我有哪里写错了么? 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北笙凉宸 2021-11-20 15:19:55

找到原因了。。。。

org.apache.activemq:BrokerName=localhost,Type=Broker

中的BrokerName与Type必须首字小写

org.apache.activemq:brokerName=localhost,type=Broker

大写小敏感。。真是没想到。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文