Enabling Distributed Configuration with Consul

Using the CLI

If you are creating your project using the Micronaut CLI, supply the config-consul feature to enable Consul’s distributed configuration in your project:

  1. $ mn create-app my-app features config-consul

To enable distributed configuration, similar to Spring Boot and Grails, you need to create a src/main/resources/bootstrap.yml configuration file and configure Consul as well as enable the configuration client:

bootstrap.yml

  1. micronaut:
  2. application:
  3. name: hello-world
  4. config-client:
  5. enabled: true
  6. consul:
  7. client:
  8. defaultZone: "${CONSUL_HOST:localhost}:${CONSUL_PORT:8500}"

Once you have enabled distributed configuration you need to store the configuration you wish to share in Consul’s Key/Value store.

There are a number of different ways to do that.