JMXConnector connector = null;
try {
HashMap environment = new HashMap();
String[] credentials = new String[]{"admin", "Password123!"};
environment.put(JMXConnector.CREDENTIALS, credentials);
// HornetQ used the protocol "remoting-jmx" and port "9999"
JMXServiceURL beanServerUrl = new JMXServiceURL("service:jmx:remoting-jmx://127.0.0.1:9990");
connector = JMXConnectorFactory.connect(beanServerUrl, environment);
MBeanServerConnection mbeanServer = connector.getMBeanServerConnection();
// The JMX object name pointed to the HornetQ JMX management
ObjectName objectName = new ObjectName("org.hornetq:type=Server,module=JMS");
// The invoked method name was "listConnectionIDs"
String[] connections = (String[]) mbeanServer.invoke(objectName, "listConnectionIDs", new Object[]{}, new String[]{});
for (String connection : connections) {
System.out.println(connection);
}
} finally {
if (connector != null) {
connector.close();
}
}
JMXConnector connector = null;
try {
HashMap environment = new HashMap();
String[] credentials = new String[]{"admin", "Password123!"};
environment.put(JMXConnector.CREDENTIALS, credentials);
// HornetQ used the protocol "remoting-jmx" and port "9999"
JMXServiceURL beanServerUrl = new JMXServiceURL("service:jmx:remoting-jmx://127.0.0.1:9990");
connector = JMXConnectorFactory.connect(beanServerUrl, environment);
MBeanServerConnection mbeanServer = connector.getMBeanServerConnection();
// The JMX object name pointed to the HornetQ JMX management
ObjectName objectName = new ObjectName("org.hornetq:type=Server,module=JMS");
// The invoked method name was "listConnectionIDs"
String[] connections = (String[]) mbeanServer.invoke(objectName, "listConnectionIDs", new Object[]{}, new String[]{});
for (String connection : connections) {
System.out.println(connection);
}
} finally {
if (connector != null) {
connector.close();
}
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
以下是 JBoss EAP 7 中 ActiveMQ Artemis 所需的同等代码示例。
JMXConnector connector = null;
try {
HashMap environment = new HashMap();
String[] credentials = new String[]{"admin", "Password123!"};
environment.put(JMXConnector.CREDENTIALS, credentials);
// ActiveMQ Artemis uses the protocol "remote+http" and port "9990"
JMXServiceURL beanServerUrl = new JMXServiceURL("service:jmx:remote+http://127.0.0.1:9990");
connector = JMXConnectorFactory.connect(beanServerUrl, environment);
MBeanServerConnection mbeanServer = connector.getMBeanServerConnection();
// The JMX object name points to the new JMX management in the `messaging-activemq` subsystem
ObjectName objectName = new ObjectName("jboss.as:subsystem=messaging-activemq,server=default");
// The invoked method name is now "listConnectionIds"
String[] connections = (String[]) mbeanServer.invoke(objectName, "listConnectionIds", new Object[]{}, new String[]{});
for (String connection : connections) {
System.out.println(connection);
}
} finally {
if (connector != null) {
connector.close();
}
}
JMXConnector connector = null;
try {
HashMap environment = new HashMap();
String[] credentials = new String[]{"admin", "Password123!"};
environment.put(JMXConnector.CREDENTIALS, credentials);
// ActiveMQ Artemis uses the protocol "remote+http" and port "9990"
JMXServiceURL beanServerUrl = new JMXServiceURL("service:jmx:remote+http://127.0.0.1:9990");
connector = JMXConnectorFactory.connect(beanServerUrl, environment);
MBeanServerConnection mbeanServer = connector.getMBeanServerConnection();
// The JMX object name points to the new JMX management in the `messaging-activemq` subsystem
ObjectName objectName = new ObjectName("jboss.as:subsystem=messaging-activemq,server=default");
// The invoked method name is now "listConnectionIds"
String[] connections = (String[]) mbeanServer.invoke(objectName, "listConnectionIds", new Object[]{}, new String[]{});
for (String connection : connections) {
System.out.println(connection);
}
} finally {
if (connector != null) {
connector.close();
}
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
请注意,新实施中的方法名称和参数已更改。您可以按照以下步骤在 JConsole 中找到新方法名称。
使用以下命令连接 JConsole:
EAP_HOME/bin/jconsole.sh
$ EAP_HOME/bin/jconsole.sh
Copy to ClipboardCopied!Toggle word wrapToggle overflow