如何获取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);
答案 0 :(得分:3)
解决方案是使用表达式:
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());
}
答案 1 :(得分:1)
我正在使用ActiveMQ 5.14.5,它使用不同的ObjectName格式通过JMX查询连接。在此版本的ActiveMQ中,与Andrew's answer等效的是:
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());
}
答案 2 :(得分:0)
在最新版本的 ActiveMQ (5.1x.x) 中,您可以使用 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
中有一些方法可以获取传输连接器,如上面的代码所示,但没有任何方法可以获取网络(也称为代理到代理)连接器的列表。>