InfluxDB2
Since Camel 3.20
Only producer is supported
This component allows you to interact with InfluxDB 2.x, a time series database. The native body type for this component is Point (the native InfluxDB class). However, it can also accept Map<String, Object> as message body, and it will get converted to Point.class, please note that the map must contain an element with CamelInfluxDB2MeasurementName as key. The other entries of the map are the fields of the point; the map itself is not changed, so it can be immutable.
Additionally, you may register your own Converters to your data type to Point, or use the (un)marshalling tools provided by Camel.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-influxdb2</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency> URI format
influxdb2://connectionBean?[options]
The producer allows sending messages to an InfluxDB configured in the registry, using the native java driver.
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 InfluxDB2 component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Autowired The com.influxdb.client.InfluxDBClient that all endpoints use. When it is set or autowired, the connectionBean of an endpoint is not looked up in the registry. The component does not close this client. | InfluxDBClient | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | 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 InfluxDB2 endpoint is configured using URI syntax:
influxdb2:connectionBean
With the following path and query parameters:
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Whether the endpoint looks up the bucket of the bucket option when it starts, and creates it in the organization of the org option when it does not exist. If autoCreateOrg is false and that organization does not exist, the endpoint fails to start. A bucket that the CamelInfluxDB2Bucket header names is not created. Not used by the PING operation. | true | boolean | |
Whether the endpoint looks up the organization of the org option when it starts, and creates it when it does not exist. An organization that the CamelInfluxDB2Org header names is not created. Not used by the PING operation. | true | boolean | |
The name of the bucket to write to. The CamelInfluxDB2Bucket header replaces this option for a write, so the option can be left out when autoCreateBucket is false. The autoCreateBucket option uses this bucket when the endpoint starts, and the endpoint fails to start without it. Not used by the PING operation. | String | ||
The operation of the producer. INSERT writes the body to the bucket. PING calls the ping endpoint of InfluxDB and sets the body to a Boolean: true when InfluxDB answered with success, false otherwise. Enum values:
| INSERT | Operation | |
The name of the organization to write to. The CamelInfluxDB2Org header replaces this option for a write, so the option can be left out when autoCreateOrg and autoCreateBucket are false. The autoCreateOrg and autoCreateBucket options use this organization when the endpoint starts: with autoCreateOrg, or with autoCreateBucket and a bucket that does not exist yet, the endpoint fails to start without it. Not used by the PING operation. | String | ||
Deprecated The name of a retention policy, which InfluxDB 1.x has and InfluxDB 2.x does not. Deprecation note: Never read by the component: the InfluxDB 2.x write API has no retention policy, retention is a property of the bucket. | default | String | |
The precision of the timestamps in a Measurement, Record, Measurements or Records body. It does not apply to a Point, a Map or a Points body, as the client writes each Point with its own precision (ns unless set with Point.time). The CamelInfluxDB2WritePrecision header replaces this option. Enum values:
| ms | WritePrecision | |
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean |
Message Headers
The InfluxDB2 component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelInfluxDB2MeasurementName (producer) Constant: | The key of the measurement name in a Map body, which the producer converts to a Point whose fields are the other entries of the Map. The producer does not read a message header of this name. | String | |
camelInfluxDB.RetentionPolicy (producer) Constant: | Deprecated The name of a retention policy, which InfluxDB 1.x has and InfluxDB 2.x does not. Deprecation note: Never read by the component: the InfluxDB 2.x write API has no retention policy, retention is a property of the bucket. | String | |
| Constant: | The name of the organization to write to, overriding the org option on the endpoint. | String | |
CamelInfluxDB2Bucket (producer) Constant: | The name of the bucket to write to, overriding the bucket option on the endpoint. | String | |
CamelInfluxDB2WritePrecision (producer) Constant: | The precision of the timestamps in a Measurement, Record, Measurements or Records body, which replaces the writePrecision option. It does not apply to a Point, a Map or a Points body. Enum values:
| WritePrecision |
Message Body
The message body at each side of the InfluxDB2 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 |
|---|---|---|
Producer input |
| A com.influxdb.client.write.Point, or the Measurement, Record, Points, Measurements or Records wrappers of the component (package org.apache.camel.component.influxdb2.data), or a Map of the field names and their values with the measurement name under the CamelInfluxDB2MeasurementName key. Text, a List or an annotated class that is not wrapped fail: wrap a line protocol String in a Record and an annotated object in a Measurement. A Point without a field that has a value (also from a Map or in Points) fails the exchange, as the client would skip it. Ping does not read the body.
|
Producer output |
| An insert leaves the body unchanged; ping gives a Boolean, true when the server answered.
|
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.
Example
Below is an example route that stores a point into the db (taking the db name from the URI) specific key:
-
Java
-
XML
-
YAML
from("direct:start")
.to("influxdb2://connectionBean?org=myOrg&bucket=myBucket"); <route>
<from uri="direct:start"/>
<to uri="influxdb2://connectionBean?org=myOrg&bucket=myBucket"/>
</route> - route:
from:
uri: direct:start
steps:
- to:
uri: influxdb2://connectionBean
parameters:
org: myOrg
bucket: myBucket Writes are synchronous
The producer writes with the synchronous write API of the InfluxDB client (WriteApiBlocking): the exchange continues when InfluxDB has answered the write request. A write that InfluxDB rejects (for example, a line it cannot parse, an unknown bucket or a token that is not authorized), or a request that cannot be sent, fails the exchange with a CamelInfluxDb2Exception whose cause is the InfluxException of the client, so the error handler of the route can redeliver it or move it to a dead letter channel.
Each exchange is one write request. To write many points with one request, send a Points, Measurements or Records body, for example, from an Aggregate EIP.
InfluxDB needs at least one field in a point, and the client skips a point without a field that has a value (no field at all, or only fields whose value is null, NaN or infinite) instead of writing it. Such a Point, also one converted from a Map or one of the points of a Points body, fails the exchange with a CamelInfluxDb2Exception, and nothing is written.
Organization and bucket at startup
When autoCreateOrg is true (the default), the endpoint looks the organization up when it starts and creates it when it does not exist. When autoCreateBucket is true (the default), it does the same for the bucket, in the organization of the endpoint. With autoCreateOrg=false, a missing bucket is created only when that organization exists, and otherwise the endpoint fails to start.
A write names the organization and the bucket, so the endpoint does not need them to be looked up: with autoCreateOrg=false and autoCreateBucket=false it does not call InfluxDB when it starts, and the route starts while InfluxDB is down. An organization or a bucket that does not exist then fails the write, and so the exchange.