簡體   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