Consul  is a distributed, highly available, datacenter-aware, service discovery and configuration system.

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

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

 

URI format

consul:apiEndpoint[?options]

Where apiEnpoint represents the consul's HTTP API the consul-component should operate on: 

Supported HTTP API are:

 

Options

Name

Group

Default

Java Type

Description

url

common

 

String

Defines the URIs the component should connect to.

keycommon StringThe default key. Can be overridden by CamelConsulKey
actionproducer StringThe default action. Can be overridden by CamelConsulAction
pingInstancecommontruebooleanConfigure if the AgentClient should attempt a ping before returning the Consul instance
valueAsStringcommonfalsebooleanDefault to transform values retrieved from Consul i.e. on KV endpoint to string.
connectTimeoutMilliscommon LongConnect timeout for OkHttpClient
readTimeoutMilliscommon LongRead timeout for OkHttpClient
writeTimeoutMilliscommon LongWrite timeout for OkHttpClient
sslContextParameterssecurity SSLContextParametersSSL configuration using an org.apache.camel.util.jsse.SSLContextParameters instance
userNamesecurity StringSets the username to be used for basic authentication
passwordsecurity StringSets the password to be used for basic authentication
aclTokensecurity StringSets the ACL token to be used with Consul
blockSecondsconsumer, watch10IntegerThe second to wait for a watch event default 10 seconds
firstIndexconsumer, watch0LongThe first index to watch for
recursiveconsumer, watchfalsebooleanRecursively watch

 

Headers

NameJava TypeDescription
CamelConsulActionStringThe action to perform
CamelConsulKeyStringThe Key on which the action should be applied
CamelConsulEventIdStringThe event id 
CamelConsulEventNameStringThe event name
CamelConsulEventLTimeLongThe event ltime
CamelConsulNodeFilterStringThe node filter
CamelConsulTagFilterStringThe tag filter
CamelConsulSessionFilterStringThe session filter
CamelConsulVersionIntegerThe data version
CamelConsulFlagsLongFlags associated with a value
CamelConsulCreateIndexLongThe internal index value that represents when the entry was created
CamelConsulLockIndexLongThe number of times this key has successfully been acquired in a lock
CamelConsulModifyIndexLongThe last index that modified this key
CamelConsulOptionsObjectOptions associated to the request
CamelConsulResultBooleantrue if the response has a result
CamelConsulSessionStringThe session id
CamelConsulValueAsStringBooleanTo transform values retrieved from Consul i.e. on KV endpoint to string.

 

KV API example:

 

CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
    public void configure() {
       from("direct:put")
            .to("consul:kv-put")
                .to("log:camel-consul?level=INFO");
    }
});

 
FluentProducerTemplate.on(context)
    .withHeader(ConsulConstants.CONSUL_ACTION, ConsulKeyValueActions.PUT)
    .withHeader(ConsulConstants.CONSUL_KEY, "mykey")
    .withBody(val)
    .to("direct:kv-put")
    .send();


 

Watch API example:

 

CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
    public void configure() {
       from("consul:kv?key=myKey&valueAsString=true")
           .to("log:camel-consul?level=INFO&showAll=true")
           .to("mock:kv-watch");
    }
});

 

 

 

  • No labels