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.
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
.
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>
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
}
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.
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
18.188.154.252