JMX
Since Camel 2.6
Only consumer is supported
Apache Camel has extensive support for JMX to allow you to monitor and control the Camel managed objects with a JMX client.
Camel also provides a JMX component that allows you to subscribe to MBean notifications. This page is about how to manage and monitor Camel using JMX.
| If you run Camel standalone with just |
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The JMX component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean |
Endpoint Options
The JMX endpoint is configured using URI syntax:
jmx:serverURL
With the following path and query parameters:
Path Parameters
| Name | Description | Default | Type |
|---|---|---|---|
The MBean server to connect to: platform for the platform MBean server of the JVM that runs Camel, or the JMX service URL of a remote MBean server, for example service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi. The monitorType option works only with platform. | String |
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
The format of the message body: xml for the notification as XML text, as defined by the notifications.xsd schema of camel-jmx, or raw for the javax.management.Notification object. Enum values:
| xml | String | |
The period at which the monitor reads the value of the observed attribute (the granularity period of the JMX monitor). Only used with monitorType. | 10000 | long | |
The type of the JMX monitor to create: counter (CounterMonitor), gauge (GaugeMonitor) or string (StringMonitor). If set, the consumer registers a monitor MBean on the platform MBean server that observes the observedAttribute of the MBean, and receives the notifications of the monitor instead of those of the MBean. Only supported when serverURL is platform. Enum values:
| String | ||
Required The domain of the ObjectName of the MBean to listen to, for example java.lang. With monitorType, the consumer also registers its monitor MBean in this domain. | String | ||
The value of the name key of the ObjectName of the MBean to listen to: the consumer uses the ObjectName objectDomain:name=objectName. Set either this option or the objectProperties option, not both. | String | ||
The name of the MBean attribute to observe. With monitorType it is required, and the monitor observes this attribute. Without monitorType and without notificationFilter, the consumer receives only the AttributeChangeNotifications of this attribute, selected further by stringToCompare. | String | ||
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
A shared thread pool that routes the notifications of the consumers that use it. If not set, each consumer creates its own single-threaded pool, which routes its notifications one at a time in the order they arrive. | ExecutorService | ||
An object that the MBean server hands back with each notification, which the consumer puts in the jmx.handback header. With monitorType this option is not used, and the header holds the monitor MBean instead. | Object | ||
A javax.management.NotificationFilter that selects the notifications to receive. It replaces the filter that the consumer builds from observedAttribute and stringToCompare, and with monitorType it selects among the notifications of the monitor. A remote MBean server receives the filter serialized and applies it itself, so its class must be on the class path of that server. | NotificationFilter | ||
The key properties of the ObjectName of the MBean to listen to, for example key.type=Threading for the ObjectName java.lang:type=Threading. Set either this option or the objectName option, not both. This is a multi-value option with prefix: key. | Map | ||
The number of seconds to wait before the next attempt to connect to a remote MBean server: at startup when testConnectionOnStartup is false, and after a lost connection when reconnectOnConnectionFailure is true. | 10 | int | |
Whether the consumer connects again to a remote MBean server when the connection is closed or fails, or notifications are lost. It tries every reconnectDelay seconds until it succeeds. When the JMX connector opens a new connection by itself, the consumer registers its listener again on that connection. | false | boolean | |
Whether the consumer fails to start when it cannot connect to a remote MBean server. If false, the consumer logs a warning and tries to connect again every reconnectDelay seconds until it succeeds. | true | boolean | |
The initial threshold of the counter monitor, which sends a notification when the counter reaches or exceeds the threshold. The value is converted to the type of the observed attribute, which must be an integer type. If not set, the threshold is 0. Only used when monitorType is counter. | int | ||
The value at which the observed counter wraps around to zero. The counter monitor sets the threshold back to initThreshold when it exceeds this value, and in difference mode adds it to a negative difference. If not set (0), the counter is taken not to wrap around. Only used when monitorType is counter. | int | ||
The value that the counter monitor adds to the threshold each time the counter reaches it, so that it sends a notification each time the counter grows by this value. If not set (0), the threshold does not change. Only used when monitorType is counter. | int | ||
Whether the counter or gauge monitor compares the difference between two successive observations of the attribute with the thresholds, instead of the value of the attribute itself. Only used when monitorType is counter or gauge. | false | boolean | |
Whether the gauge monitor sends a notification when the observed value rises to or above thresholdHigh. After that it sends the next high notification only once the value has fallen to or below thresholdLow. When monitorType is gauge, notifyHigh, notifyLow or both must be true. | false | boolean | |
Whether the gauge monitor sends a notification when the observed value falls to or below thresholdLow. After that it sends the next low notification only once the value has risen to or above thresholdHigh. When monitorType is gauge, notifyHigh, notifyLow or both must be true. | false | boolean | |
The high threshold of the gauge monitor, converted to the type of the observed attribute. It must not be lower than thresholdLow. Required when monitorType is gauge. | Double | ||
The low threshold of the gauge monitor, converted to the type of the observed attribute. It must not be higher than thresholdHigh. Required when monitorType is gauge. | Double | ||
The password to authenticate with on a remote MBean server. The consumer passes user and password to the JMX connector as its credentials. Not used for the platform MBean server. | String | ||
The user name to authenticate with on a remote MBean server. The consumer passes user and password to the JMX connector as its credentials. Not used for the platform MBean server. | String | ||
Whether to receive a notification when the value of the observed attribute differs from stringToCompare. With monitorType string, the string monitor sends one each time the value starts to differ. Without monitorType, the consumer then receives the attribute changes whose new value differs from stringToCompare, instead of those whose new value matches it. | false | boolean | |
Whether the string monitor sends a notification each time the value of the observed attribute starts to match stringToCompare. When monitorType is string, notifyMatch, notifyDiffer or both must be true. Without monitorType this option is not used: the consumer receives the matching attribute changes unless notifyDiffer is true. | false | boolean | |
The text that the value of the observed attribute is compared with. Required when monitorType is string. Without monitorType, the consumer compares it with the new value of each AttributeChangeNotification of the observedAttribute (the text null matches a null value), and receives every change of the attribute when this option is not set. | String |
Message Headers
The JMX component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
| Constant: | The handback object that the consumer registered with its notification listener: the value of the handback option, or the monitor MBean when monitorType is set. | Object |
Message Body
The message body at each side of the JMX component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Consumer |
| The notification as XML text, such as an AttributeChangeNotification or a MonitorNotification element; with format=raw the Notification object. The handback object is in the jmx.handback header.
|
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Usage
The JMX consumer receives the notifications of an MBean. With monitorType, it creates a JMX monitor that watches an attribute, and sends a notification when the value crosses a threshold. jmx:platform is the MBean server of the JVM that runs Camel. The route below gets a notification when the JVM has more than 200 threads. The gauge sends it again only after the value has gone below thresholdLow:
- route:
from:
uri: jmx:platform
parameters:
objectDomain: java.lang
key.type: Threading
monitorType: gauge
observedAttribute: ThreadCount
granularityPeriod: 5000
notifyHigh: true
thresholdHigh: 200
thresholdLow: 100
steps:
- log:
message: "The JVM has more than 200 threads: ${body}" The message body is the notification as XML. Set format to raw to get the notification object.