Consul Configuration Store

The Consul Configuration Store extends the Vert.x Configuration Retriever and provides the way to retrieve configuration from a Consul.

Using the Consul Configuration Store

To use the Consul Configuration Store, add the following dependency to the dependencies section of your build descriptor:

  • Maven (in your pom.xml):

<dependency>
 <groupId>io.vertx</groupId>
 <artifactId>vertx-config-consul</artifactId>
 <version>4.0.0.CR1</version>
</dependency>
<dependency>
 <groupId>io.vertx</groupId>
 <artifactId>vertx-config</artifactId>
 <version>4.0.0.CR1</version>
</dependency>
  • Gradle (in your build.gradle file):

compile 'io.vertx:vertx-config:4.0.0.CR1'
compile 'io.vertx:vertx-config-consul:4.0.0.CR1'

Configuring the store

Once added to your classpath or dependencies, you need to configure the ConfigRetriever to use this store:

ConfigStoreOptions store = new ConfigStoreOptions()
    .setType("consul")
    .setConfig(new JsonObject()
      .put("host", "localhost")
      .put("port", 8500)
      .put("prefix", "foo")
      .put("raw-data", false)
    );

ConfigRetriever retriever = ConfigRetriever.create(vertx,
    new ConfigRetrieverOptions().addStore(store));

The store configuration is used to create an instance of ConsulClient. Check the documentation of the Vert.x Consul Client for further details. And this is the parameters specific to the Consul Configuration Store:

prefix

A prefix that will not be taken into account when building the configuration tree. Defaults to empty.

delimiter

Symbol that used to split keys in the Consul storage to obtain levels in the configuration tree. Defaults to "/".

raw-data

If raw-data is true no attempts to convert values is made, and you’ll be able to get raw values using config.getString(key). Defaults to true.