Posted In: Micro, Service

Micro services – configuration management using CONSUL

This post shows one of the ways to create micro services architecture with enterprise level configuration services

KV Storage – Flexible key/value store for dynamic configuration, feature flagging, coordination, leader election and more. Long poll for near-instant notification of configuration changes.
Install CONSUL from https://www.consul.io/downloads.html

Steps

1. Start consul. (Click on consul.exe on windows)
2. Add consul-api java client library to maven
3. Add and fetch configuration parameters


<dependency>
  <groupId>com.ecwid.consul</groupId>
  <artifactId>consul-api</artifactId>
  <version>1.3.0</version>
</dependency>
package com.javausecase.consul;

import org.junit.Test;

import com.ecwid.consul.v1.ConsulClient;
import com.ecwid.consul.v1.Response;
import com.ecwid.consul.v1.kv.model.GetValue;

public class App {

	@Test
	public void main() throws Exception {
		ConsulClient client = new ConsulClient("localhost");
		client.setKVValue("com.javausecase.db.jndi", "jdbc/javadb");
		client.setKVValue("com.javausecase.db.schema", "javausecase");

		Response<GetValue> keyValueResponse = client
				.getKVValue("com.javausecase.db.jndi");
		System.out.println(keyValueResponse.getValue().getKey() + ": "
				+ keyValueResponse.getValue().getDecodedValue());
	}
}

Tags:

by , on February 20th, 2018

  • Categories