Switch branches/tags
Nothing to show
Find file History
Latest commit f1026f4 Nov 2, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/main Updated schema version. Sep 15, 2017
README.md Update README.md Nov 2, 2018
pom.xml Upped KumuluzEE version of the samples Oct 12, 2018


KumuluzEE Config sample with etcd

Build a REST service which utilizes KumuluzEE Config to access configuration properties stored in etcd and pack it as a KumuluzEE microservice

The objective of this sample is to show how to develop a microservice that uses KumuluzEE Config extension to access configuration properties stored in etcd. In this sample we develop a simple REST service that returns a list of configuration properties from all available configuration sources and pack it as KumuluzEE microservice. This tutorial will guide you through all the necessary steps. You will first add KumuluzEE dependencies into pom.xml. To develop the REST service, you will use the standard JAX-RS 2 API. Required knowledge: basic familiarity with JAX-RS 2 and basic concepts of REST, JSON, yaml and etcd.


In order to run this example you will need the following:

  1. Java 8 (or newer), you can use any implementation:

    • If you have installed Java, you can check the version by typing the following in a command line:

      java -version
  2. Maven 3.2.1 (or newer):

    • If you have installed Maven, you can check the version by typing the following in a command line:

      mvn -version
  3. Git:

    • If you have installed Git, you can check the version by typing the following in a command line:

      git --version


To run this sample you will need an etcd instance. Note that such setup with only one etcd node is not viable for production environments, but only for developing purposes. Here is an example on how to quickly run an etcd instance with docker:

 $ docker run -d -p 2379:2379 \
     --name etcd \
     --volume=/tmp/etcd-data:/etcd-data \
     quay.io/coreos/etcd:latest \
     /usr/local/bin/etcd \
     --name my-etcd-1 \
     --data-dir /etcd-data \
     --listen-client-urls \
     --advertise-client-urls \
     --listen-peer-urls \
     --initial-advertise-peer-urls \
     --initial-cluster my-etcd-1= \
     --initial-cluster-token my-etcd-token \
     --initial-cluster-state new \
     --auto-compaction-retention 1 \


The example uses maven to build and run the microservice.

  1. Build the sample using maven:

    $ cd kumuluzee-config-etcd
    $ mvn clean package
  2. Run the sample:

  • Uber-jar:

    $ java -jar target/${project.build.finalName}.jar

    in Windows environemnt use the command

    java -jar target/${project.build.finalName}.jar
  • Exploded:

    $ java -cp target/classes:target/dependency/* com.kumuluz.ee.EeApplication

    in Windows environment use the command

    java -cp target/classes;target/dependency/* com.kumuluz.ee.EeApplication

The application/service can be accessed on the following URL:

To shut down the example simply stop the processes in the foreground.


This tutorial will guide you through the steps required to create a simple REST service that exposes configuration properties retrieved with a built-in configuration framework and KumuluEE config extension. We will develop a simple REST service with just one resource:

We will follow these steps:

  • Create a Maven project in the IDE of your choice (Eclipse, IntelliJ, etc.)
  • Add Maven dependencies to KumuluzEE and include KumuluzEE components (Core, Servlet, JAX-RS and CDI)
  • Add Maven dependency to KumuluzEE Config
  • Define our configuration properties in configuration file
  • Implement the service using standard JAX-RS 2
  • Build the microservice
  • Run it
  • Dynamically change configuration properties in etcd

Add Maven dependencies

Add the KumuluzEE BOM module dependency to your pom.xml file:


Add the kumuluzee-core, kumuluzee-servlet-jetty, kumuluzee-jax-rs-jersey and kumuluzee-cdi-weld dependencies:


Alternatively, we could add the kumuluzee-microProfile-1.0, which adds the MicroProfile 1.0 dependencies (JAX-RS, CDI, JSON-P, and Servlet).

Add dependency to KumuluzEE Config extension:


Add the kumuluzee-maven-plugin build plugin to package microservice as uber-jar:


or exploded:


Implement the service

Define KumuluzEE configuration as well as your custom configuration properties in a config.yaml configuration file:

  name: customer-service
  version: 1.0.0
    name: dev
    start-retry-delay-ms: 500
    max-retry-delay-ms: 900000

  string-property: Monday
  boolean-property: true
  integer-property: 23

Register your module as JAX-RS service and define the application path. You could do that in web.xml or for example with the @ApplicationPath annotation:

public class ConfigApplication extends Application {

Implement an application scoped CDI bean that will automatically load and hold our configuration properties. It shall be annotated with @ConfigBundle annotation whose value represents the prefix for the configuration properties keys. Add a @ConfigValue(watch = true) to enable watch on the key. This will monitor the changes of this key in etcd and automatically update the value in the configuration bean.

public class ConfigProperties {

    @ConfigValue(watch = true)
    private String stringProperty;
    private Boolean booleanProperty;
    private Integer integerProperty;
    // get and set methods

Implement a JAX-RS resource that will expose retrieved configuration properties on GET request:

public class ConfigResource {

    private ConfigProperties properties;

    public Response test() {
        String response =
                "{" +
                        "\"stringProperty\": \"%s\"," +
                        "\"booleanProperty\": %b," +
                        "\"integerProperty\": %d" +

        response = String.format(

        return Response.ok(response).build();

To build the microservice and run the example, use the commands as described in previous sections.

Since we have not defined any configuration properties in etcd, GET http://localhost:8080/v1/config will return configuration properties from configuraiton file. We can now try and add some values in etcd. Since we enabled watch on the field stringProperty, it will be dynamically updated on any change in etcd. We can add a value to etcd with the following command:

 $ docker exec etcd etcdctl --endpoints // set /environments/dev/services/customer-service/1.0.0/config/rest-config/string-property test_string

Access the config endpoint again and you will get an updated value from etcd.