Enabling JMX for Java Camel Routes and CXF Services
JMX configuration for Camel routes
Apache Camel has support for JMX and allows you to monitor a Camel managed object (for example, routes). By default, a JMX agent is enabled in Camel which means that the Camel runtime creates and registers MBean management objects with a MBeanServer instance in the VM. But if you would like to configure a JMX agent (for example to use a custom port in JMX URL) the best way to do it is adding a jmxAgent element inside the camelContext element in Spring configuration:
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<jmxAgent id="agent" mbeanObjectDomainName="your.domain.name">
...
<camelContext>
The default JMX configuration is used in both examples, but you can also configure it:
<jmxAgent id="agent" registryPort="port number" createConnector="true">
createConnector means that we should create a JMX connector (to allow remote management) for the MBeanServer.registryPort is the port for JMX.
You can set hostName and domainName for DefaultManagementNamingStrategy. As a default, hostName is the computer name and domainName is org.apache.camel
<bean id="naming"
class="org.apache.camel.management.DefaultManagementNamingStrategy">
<property name="hostName" value="localhost"/>
<property name="domainName" value="org.apache.camel">
</bean>
To configure specific definitions for the Camel route object use the properties:
Property Name | Description |
---|---|
org.apache.camel |
domain name |
routes |
Camel routes type |
context |
Camel context name |
name |
route name |
You can find further information about configuring Camel JMX agent at the "Camel" site http://camel.apache.org/camel-jmx.html.
JMX configuration for CXF services
Each server type defines several service types such as EJBs, Connection Pools, JMS Queues, and so on. The plugin defines additional service types to provide management of CXF via custom MBeans. The service element defines a service type, for example:
Plugin object section:
<service name="CXF all services monitoring">
<property name="OBJECT_NAME"
value='org.apache.cxf:bus.id=*,type=Performance.Counter.Server,service=*,
port=*,operation=*'/>
<metrics include="cxf"/>
<plugin type="autoinventory" />
</service>
In order to access custom MBeans, the plugin must define its JMX ObjectName to be used with various MBeanServer interface methods. Only one ObjectName is defined per service type using the property tag within the service tag.
To configure specific definitions for the CXF service object use properties:
Property Name | Description |
---|---|
org.apache.cxf:bus.id | id of specific CXF bus |
service | service endpoint name |
port | service port name |
operation | service operation name |
To enable JMX integration for CXF you need to declare the following bean in service Spring configuration:
<bean id="org.apache.cxf.management.InstrumentationManager"
class="org.apache.cxf.management.jmx.InstrumentationManagerImpl">
<property name="bus" ref="cxf" />
<property name="usePlatformMBeanServer" value="true" />
<property name="createMBServerConnectorFactory" value="false" />
<property name="enabled" value="true" />
</bean>
To avoid any unnecessary runtime overhead, the performance counters measuring response time are disabled by default. To collect statistics for running sevices define the following bean:
<bean id="CounterRepository"
class="org.apache.cxf.management.counters.CounterRepository">
<property name="bus" ref="cxf" />
</bean>
For further information about configuring JMX in CXF you can find at Apache CXF.