Etcd v3

Since Camel 3.19

Both producer and consumer are supported

The camel Etcd component allows you to work with Etcd, a distributed reliable key-value store.

Maven users will need to add the following dependency to their pom.xml for this component:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-etcd3</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

URI Format

etcd3:path[?options]

Configuring Options

Camel components are configured on two separate levels:

  • component level

  • endpoint level

Configuring Component Options

The component level is the highest level which holds general and common configurations that are inherited by the endpoints. 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.

Configuring components can be done with the Component DSL, in a configuration file (application.properties|yaml), or directly with Java code.

Configuring Endpoint Options

Where you find yourself configuring the most is on endpoints, as endpoints often have many options, which allows you to configure what you need the endpoint to do. The options are also categorized into whether the endpoint is used as consumer (from) or as a producer (to), or used for 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, which allows to not hardcode urls, port numbers, sensitive information, and other settings. In other words placeholders allows to externalize the configuration from your code, and gives more flexibility and reuse.

The following two sections lists all the options, firstly for the component followed by the endpoint.

Component Options

The Etcd v3 component supports 25 options, which are listed below.

Name Description Default Type

configuration (common)

Component configuration.

Etcd3Configuration

endpoints (common)

Configure etcd server endpoints using the IPNameResolver.

Etcd3Constants.ETCD_DEFAULT_ENDPOINTS

String[]

keyCharset (common)

Configure the charset to use for the keys.

UTF-8

String

namespace (common)

Configure the namespace of keys used. / will be treated as no namespace.

String

prefix (common)

To apply an action on all the key-value pairs whose key that starts with the target path.

false

boolean

bridgeErrorHandler (consumer)

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

fromIndex (consumer (advanced))

The index to watch from.

0

long

lazyStartProducer (producer)

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

valueCharset (producer)

Configure the charset to use for the values.

UTF-8

String

authHeaders (advanced)

Configure the headers to be added to auth request headers.

Map

authority (advanced)

Configure the authority used to authenticate connections to servers.

String

autowiredEnabled (advanced)

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

connectionTimeout (advanced)

Configure the connection timeout.

Duration

headers (advanced)

Configure the headers to be added to http request headers.

Map

keepAliveTime (advanced)

Configure the interval for gRPC keepalives. The current minimum allowed by gRPC is 10 seconds.

30 seconds

Duration

keepAliveTimeout (advanced)

Configure the timeout for gRPC keepalives.

10 seconds

Duration

loadBalancerPolicy (advanced)

Configure etcd load balancer policy.

String

maxInboundMessageSize (advanced)

Configure the maximum message size allowed for a single gRPC frame.

Integer

retryDelay (advanced)

Configure the delay between retries in milliseconds.

500

long

retryMaxDelay (advanced)

Configure the max backing off delay between retries in milliseconds.

2500

long

retryMaxDuration (advanced)

Configure the retries max duration.

Duration

servicePath (cloud)

The path to look for service discovery.

/services/

String

password (security)

Configure etcd auth password.

String

sslContext (security)

Configure SSL/TLS context to use instead of the system default.

SslContext

userName (security)

Configure etcd auth user.

String

Endpoint Options

The Etcd v3 endpoint is configured using URI syntax:

etcd3:path

with the following path and query parameters:

Path Parameters (1 parameters)

Name Description Default Type

path (common)

The path the endpoint refers to.

String

Query Parameters (25 parameters)

Name Description Default Type

endpoints (common)

Configure etcd server endpoints using the IPNameResolver.

Etcd3Constants.ETCD_DEFAULT_ENDPOINTS

String[]

keyCharset (common)

Configure the charset to use for the keys.

UTF-8

String

namespace (common)

Configure the namespace of keys used. / will be treated as no namespace.

String

prefix (common)

To apply an action on all the key-value pairs whose key that starts with the target path.

false

boolean

bridgeErrorHandler (consumer (advanced))

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

exceptionHandler (consumer (advanced))

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

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly

  • InOut

ExchangePattern

fromIndex (consumer (advanced))

The index to watch from.

0

long

valueCharset (producer)

Configure the charset to use for the values.

UTF-8

String

lazyStartProducer (producer (advanced))

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

authHeaders (advanced)

Configure the headers to be added to auth request headers.

Map

authority (advanced)

Configure the authority used to authenticate connections to servers.

String

connectionTimeout (advanced)

Configure the connection timeout.

Duration

headers (advanced)

Configure the headers to be added to http request headers.

Map

keepAliveTime (advanced)

Configure the interval for gRPC keepalives. The current minimum allowed by gRPC is 10 seconds.

30 seconds

Duration

keepAliveTimeout (advanced)

Configure the timeout for gRPC keepalives.

10 seconds

Duration

loadBalancerPolicy (advanced)

Configure etcd load balancer policy.

String

maxInboundMessageSize (advanced)

Configure the maximum message size allowed for a single gRPC frame.

Integer

retryDelay (advanced)

Configure the delay between retries in milliseconds.

500

long

retryMaxDelay (advanced)

Configure the max backing off delay between retries in milliseconds.

2500

long

retryMaxDuration (advanced)

Configure the retries max duration.

Duration

servicePath (cloud)

The path to look for service discovery.

/services/

String

password (security)

Configure etcd auth password.

String

sslContext (security)

Configure SSL/TLS context to use instead of the system default.

SslContext

userName (security)

Configure etcd auth user.

String

Message Headers

The Etcd v3 component supports 5 message header(s), which is/are listed below:

Name Description Default Type

CamelEtcdAction (producer)

Constant: ETCD_ACTION

The action to perform. Supported values: set get delete.

String

CamelEtcdPath (common)

Constant: ETCD_PATH

The target path.

String

CamelEtcdIsPrefix (producer)

Constant: ETCD_IS_PREFIX

To apply an action on all the key-value pairs whose key that starts with the target path.

Boolean

CamelEtcdKeyCharset (producer)

Constant: ETCD_KEY_CHARSET

The charset to use for the keys.

String

CamelEtcdValueCharset (producer)

Constant: ETCD_VALUE_CHARSET

The charset to use for the values.

String

Producer Operations (Since 3.20)

The following ETCD operations are currently supported. Simply set the exchange header with a key of "CamelEtcdAction" and a value set to one of the following.

operation input message body output message body description

set

String value of the key-value pair to put

PutResponse result of a put operation

Puts a new key-value pair into etcd where the option "path" or the exchange header "CamelEtcdPath" is the key. You can set the key charset by setting the exchange header with the key "CamelEtcdKeyCharset". You can set the value charset by setting the exchange header with the key "CamelEtcdValueCharset".

get

None

GetResponse result of the get operation

Retrieves the key-value pair(s) that match with the key corresponding to the option "path" or the exchange header "CamelEtcdPath". You can set the key charset by setting the exchange header with the key "CamelEtcdKeyCharset". You indicate if the key is a prefix by setting the exchange header with the key "CamelEtcdIsPrefix" to true.

delete

None

DeleteResponse result of the delete operation

Deletes the key-value pair(s) that match with the key corresponding to the option "path" or the exchange header "CamelEtcdPath". You can set the key charset by setting the exchange header with the key "CamelEtcdKeyCharset". You indicate if the key is a prefix by setting the exchange header with the key "CamelEtcdIsPrefix" to true.

== Consumer (Since 3.20)

The consumer of the etcd components allows to watch changes on the matching key-value pair(s). One exchange is created per event with the header "CamelEtcdPath" set to the path of the corresponding key-value pair and the body of type WatchEvent.

You can set the key charset by setting the exchange header with the key "CamelEtcdKeyCharset". You indicate if the key is a prefix by setting the exchange header with the key "CamelEtcdIsPrefix" to true.

By default, the consumer receives only the latest changes, but it is also possible to start watching events from a specific revision by setting the option "fromIndex" to the expected starting index.

== AggregationRepository

The Etcd3 component provides an AggregationStrategy to use Etcd as the backend datastore.

== RoutePolicy (Since 3.20)

The Etcd3 component provides a RoutePolicy to use Etcd as clustered lock.