简体   繁体   English

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

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

How do I get the list of the connections to the OpenWire connector of ActiveMQ?如何获取到 ActiveMQ 的 OpenWire 连接器的连接列表? JConsole is able to list the connections, but I don't see which "view" I can use to get the list: JConsole 能够列出连接,但我看不到我可以使用哪个“视图”来获取列表:

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

I tried "ConnectorViewMBean", but the operations on it don't allow me to list the connections:我试过“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);

The solution was the usage of an expression:解决方案是使用表达式:

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

I'm using ActiveMQ 5.14.5, which uses a different ObjectName format for querying connections via JMX.我使用的是 ActiveMQ 5.14.5,它使用不同的 ObjectName 格式通过 JMX 查询连接。 The equivalent to Andrew's answer in this version of ActiveMQ is:与此版本的 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());
}

In the most recent versions of ActiveMQ (5.1xx), you can use the BrokerViewMBean to get a map of transport connectors:在最新版本的 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
 }

Check also out ConnectorViewMBean .另请查看ConnectorViewMBean

However, while there are methods in BrokerViewMBean to get transport connectors, as demonstrated in the above code, there aren't any to get a list of network (aka broker-to-broker) connectors.然而,虽然BrokerViewMBean有一些方法可以获取传输连接器,如上面的代码所示,但没有任何方法可以获取网络(也称为代理到代理)连接器的列表。

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

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