Reputation: 2765
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);
Upvotes: 3
Views: 4696
Reputation: 41
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.
Upvotes: 0
Reputation: 867
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());
}
Upvotes: 1
Reputation: 2765
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());
}
Upvotes: 3