179.4.3. 在 Java 虚拟机中查找 MBeanServer

每个 CamelContext 都可以在 InstrumentationLifecycleStrategy 中嵌套有 InstrumentationAgent 实例。InstrumentationAgent 是接口带有 MBeanServer 来注册 / unregister Camel MBeans 的对象。多个 CamelContexts/InstrumentationAgents 可以 / 应该共享 MBeanServer。默认情况下,Camel 运行时选择 MBeanServer Factory.findMBeanServer 方法(与 org.apache.camel 的默认域名匹配)返回的第一个 MBean Server。

您可能需要更改默认域名,使其与已在应用程序中使用的 MBeanServer 实例匹配。特别是,如果您的 MBeanServer 连接到 JMX 连接器服务器,则不需要在 Camel 中创建连接器服务器。

您可以通过系统属性配置匹配的默认域名。

-Dorg.apache.camel.jmx.mbeanServerDefaultDomain=<your.domain.name>

或者,通过在 Spring 配置中添加 camelContext 元素中的 jmxAgent 元素:

<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
  <jmxAgent id="agent" mbeanServerDefaultDomain="your.domain.name"/>
    ...
</camelContext>

如果没有找到匹配的 MBeanServer,则会创建一个新 MBeanServer,并根据上面提到的默认配置设置了新的 'MBeanServer's 默认域名。

当需要设置系统属性来管理 JVM MBeans 时,也可以使用 PlatformMBeanServerMBeanServer 默认域名配置会被忽略,因为它不适用。

小心

从下一个版本(1.5)开始,使用PlatformMBeanServer 的默认值将变为 true。您可以使用 platform MBeanServer 将 属性设置为 false 以禁用。

-Dorg.apache.camel.jmx.usePlatformMBeanServer=True

或者,通过在 Spring 配置中添加 camelContext 元素中的 jmxAgent 元素:

<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
  <jmxAgent id="agent" usePlatformMBeanServer="true"/>
    ...
</camelContext>