4.10. JMX 管理更改


JBoss EAP 6 中的 HornetQ 组件提供了自己的 JMX 管理;但是,不建议使用,现在已弃用且不再受支持。如果您依赖 JBoss EAP 6 中的此功能,您必须迁移管理工具,以使用 JBoss EAP 管理 CLI 或 JBoss EAP 7 提供的 JMX 管理工具。

您还必须升级客户端库,以使用 JBoss EAP 7 附带的 jboss-client.jar。

以下是 JBoss EAP 6 中使用的 HornetQ JMX 管理代码示例。

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 Clipboard Toggle word wrap

以下是 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();
   }
}
Copy to Clipboard Toggle word wrap

请注意,新实施中的方法名称和参数已更改。您可以按照以下步骤在 JConsole 中找到新方法名称。

  1. 使用以下命令连接 JConsole:

    $ EAP_HOME/bin/jconsole.sh
    Copy to Clipboard Toggle word wrap
  2. 连接到 JBoss EAP 本地进程.请注意,它应当以"jboss-modules.jar"开头。
  3. MBeans 选项卡中,选择 jboss.as messaging-activemq default Operations 以显示方法名称和属性列表。
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat