Disabling JMX

Camel, by default, enables JMX for all routes and endpoints it creates by default. Sometimes, such as when you are performance testing Camel, you do not want any of the JMX metric-gathering to add any extra overhead, so you may want to disable JMX. In general, it is a good idea to leave JMX enabled, as you will find it useful to help diagnose any runtime issues.

This recipe shows you how to disable JMX.

Getting ready

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

How to do it...

In the XML DSL, create a jmxAgent element within the camelContext element, and set disabled to true:

<camelContext xmlns="http://camel.apache.org/schema/spring">
  <jmxAgent id="agent" disabled="true"/>
  <!-- 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 call disableJMX() 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();

  // disable JMX - call before context.start()
  context.disableJMX();

  // add routes hereā€¦

  // start the context
  context.start();

  // do stuff

}

Note

It is important that you call disableJMX as soon as possible after you create your Camel context, as Camel will internally setup JMX lifecycle and other settings as a part of its default setup.

How it works...

Camel by default will set up internal lifecycle listeners that will create JMX MBeans as endpoints, routes, and so on get created. Setting JMX as disabled will remove these listeners, disabling the creation of Camel specific MBeans.

Your application, into which Camel is embedded, can still use JMX. The preceding steps only stop Camel from instantiating JMX MBeans.

There's more...

You can also disable Camel's JMX usage by setting a system property at startup time as follows:

# java -jar -Dorg.apache.camel.jmx.disabled=true MyCamelApp.jar
..................Content has been hidden....................

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