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

发布于 2024-12-04 12:10:52 字数 549 浏览 0 评论 0原文

如何获取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);

How do I get the list of the connections to the OpenWire connector of ActiveMQ?
JConsole is able to list the connections, but I don't see which "view" I can use to get the list:

Example ObjectName of a connection:
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:

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

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

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

发布评论

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

评论(3

星星的軌跡 2024-12-11 12:10:53

我使用的是 ActiveMQ 5.14.5,它使用不同的 ObjectName 格式通过 JMX 查询连接。在此版本的 ActiveMQ 中,相当于 Andrew 的答案 是:

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

I'm using ActiveMQ 5.14.5, which uses a different ObjectName format for querying connections via JMX. The equivalent to Andrew's answer in this version of ActiveMQ is:

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());
}
淡淡離愁欲言轉身 2024-12-11 12:10:53

在最新版本的 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 中有一些方法可以获取传输连接器(如上面的代码所示),但没有任何方法可以获取网络(也称为代理到代理)连接器的列表。

In the most recent versions of ActiveMQ (5.1x.x), you can use the BrokerViewMBean to get a map of transport connectors:

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.

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 (a.k.a. broker-to-broker) connectors.

寂寞美少年 2024-12-11 12:10:52

解决方案是使用表达式:

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

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