Configuring JMX

Camel, by default, enables JMX for all routes and endpoints it creates by default. This recipe shows you how to configure Camel's interaction with JMX.

Getting ready

The Java code for this recipe is located in the org.camelcookbook.monitoring.jmx package. The Spring XML files are located under src/main/resources/META-INF/spring and prefixed with jmx.

How to do it...

In the XML DSL, create a jmxAgent element within the camelContext element, and configure the Camel JMX options:

<camelContext xmlns="http://camel.apache.org/schema/spring">
  <jmxAgent id="agent"
            connectorPort="1099"
            createConnector="false"
            usePlatformMBeanServer="true"
            serviceUrlPath="/jmxrmi/camel"
            loadStatisticsEnabled="true"
            statisticsLevel="All"/>
  <!-- route definitions here -->
</camelContext>

Note

You must set the id attribute in the jmxAgent element otherwise you will get a validation error at startup. It does not matter what value you assign.

If you are not using Spring, Blueprint, or other dependency injection frameworks to configure your Camel context, then you need to configure JMX on your created context before you start it. See the Using Camel in a Java application recipe in Chapter 1, Structuring Routes for more details on bootstrapping Camel from your Java application.

public static void main(String[] args) throws Exception {
  final CamelContext context = new DefaultCamelContext();

  // configure JMX settings
  final ManagementStrategy managementStrategy =
    context.getManagementStrategy();
  managementStrategy.setStatisticsLevel(
    ManagementStatisticsLevel.All);
  managementStrategy.setLoadStatisticsEnabled(true);

  final ManagementAgent managementAgent =
    managementStrategy.getManagementAgent();
  managementAgent.setConnectorPort(1099);
  managementAgent.setServiceUrlPath("/jmxrmi/camel");
  managementAgent.setCreateConnector(false);
  managementAgent.setUsePlatformMBeanServer(true);

  // add Routes hereā€¦

  // start the context
  context.start();

  // do stuff
}

Note

You should configure Camel's JMX interaction before creating any routes or endpoints so that all of your JMX settings are consistently applied to all of your Camel MBeans.

Do not configure JMX within your RouteBuilder implementations as you will not be able to guarantee the order or timing of that code getting called, which will cause unexpected behavior within you application.

How it works...

Camel, by default, will set up internal lifecycle listeners that will create JMX MBeans as endpoints, routes, and so on. The Camel JMX configuration settings influence how Camel internally creates and configures JMX MBeans for routes and endpoints it creates.

How it works...

There's more...

The majority of the Camel JMX settings can be configured from system properties provided at application startup, that is, on the command line. These Camel JMX system properties are prefixed with org.apache.camel.jmx. See the Camel JMX documentation for details on system property names and values.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.186.79