繁体   English   中英

ActiveMQ:通过 JMX 获取连接列表?

[英]ActiveMQ: Get list of connections through JMX?

如何获取到 ActiveMQ 的 OpenWire 连接器的连接列表? JConsole 能够列出连接,但我看不到我可以使用哪个“视图”来获取列表:

连接的示例 ObjectName: org.apache.activemq:BrokerName=localhost,Type=Connection,ConnectorName=openwire,Connection=toto

我试过“ConnectorViewMBean”,但对它的操作不允许我列出连接:

ObjectName name = new ObjectName("org.apache.activemq:BrokerName=localhost,Type=Connection,ConnectorName=openwire"); 
mbsc.getMBeanInfo(name); 
ConnectorViewMBean view = JMX.newMBeanProxy(mbsc, name, ConnectorViewMBean.class);

解决方案是使用表达式:

ObjectName connectionNames = 
      new ObjectName("org.apache.activemq:BrokerName=localhost," + 
                     "Type=Connection,ConnectorName=openwire,Connection=*");

Set<ObjectName> names = mbsc.queryNames(connectionNames, null); 
for(ObjectName name : names) { 
   logger.error("Name: "+name.getCanonicalName()); 
} 

我使用的是 ActiveMQ 5.14.5,它使用不同的 ObjectName 格式通过 JMX 查询连接。 与此版本的 ActiveMQ 中安德鲁的回答等效是:

final JMXServiceURL url       = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
final JMXConnector  connector = JMXConnectorFactory.connect(url, null);
connector.connect();

final ObjectName connectionName = new ObjectName(
    "org.apache.activemq:type=Broker," +
    "brokerName=localhost,"            +
    "connector=clientConnectors,"      +
    "connectorName=openwire,"          +
    "connectionViewType=clientId,"     +
    "connectionName=*"
);

final MBeanServerConnection mbsc  = connector.getMBeanServerConnection();
final Set<ObjectName>       names = mbsc.queryNames(connectionName, null);
for (final ObjectName name : names) {
    System.out.println(name.getCanonicalName());
}

在最新版本的 ActiveMQ (5.1xx) 中,您可以使用BrokerViewMBean来获取传输连接器的映射:

Map<String, String[]> env = new HashMap<>();
String[] creds = {brokerUsername, brokerPassword};
env.put(JMXConnector.CREDENTIALS, creds);

final String managementURL = "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi";
try (JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(managementURL, env)) {
   ObjectName on = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost");
   BrokerViewMBean broker = MBeanServerInvocationHandler.newProxyInstance(connector.getMBeanServerConnection(), on, BrokerViewMBean.class, false);
   Map<String, String> transportConnectors = broker.getTransportConnectors();
   // broker.getTransportConnectorsByType("tcp"); // openwire
   // broker.addConnector(String discoveryAddress);
   // broker.removeConnector(String connectorName);
 } catch (MalformedObjectNameException ex) {
    // log error
 } catch (IOException ex) {
    // log error
 } catch (Exception ex) {
    // log error
 }

另请查看ConnectorViewMBean

然而,虽然BrokerViewMBean有一些方法可以获取传输连接器,如上面的代码所示,但没有任何方法可以获取网络(也称为代理到代理)连接器的列表。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM