Skip to main content

Centralized configuration using Spring Cloud Config


In this blog we will be focusing on centralized configuration using Spring Cloud Config project.
For single standalone application we can keep all required configuration bundle with application itself.  However, when we have more than one application, say in a microservice architecture, a better alternative would be to manage the configurations centrally.
With the Config Server we have a central place to manage external properties for applications with support for different environments. Configuration files in several formats like YAML or properties are added to a Git repository.

Features

Spring Cloud Config Server features:
  • HTTP, resource-based API for external configuration (name-value pairs, or equivalent YAML content)
  • Encrypt and decrypt property values (symmetric or asymmetric)
  • Embeddable easily in a Spring Boot application using @EnableConfigServer
Config Client features (for Spring applications):
  • Bind to the Config Server and initialize Spring Environment with remote property sources
  • Encrypt and decrypt property values (symmetric or asymmetric)

Use case :
  • We will keep application configuration file on GIT https://github.com/ketan-gote/config
  • Config-Server : This application serves all the application properties on REST.
  • Config-Client : This application talks to Config-Server and get the application properties during bootstrap.
Note : Here we will not focus securing properties files or REST calls, Please check Spring Cloud Config for more on that.

Centralized configuration on GIT:
URL: https://github.com/ketan-gote/config
It contains configclient.yml














Config Server
This application connects to git and serves configuration to required application.
Dependencies:

application.yml (config file) : This will have from cloud config url, in our case its git.


Above URI is public, if its private you will required to provide username/password as below.
For development purpose you will required to keep config files locally, which can be done as below (here we have used properties file instead of yml)


Below is code for Spring-Boot application:



Start the application and enter http://localhost:8081/configclient/default in browser.Config file on git is now available on REST call.



Config-Client
This is also spring boot application, which communicates to config-server for its required configuration.
Here we have created one rest endpoint which will display properties.
Dependencies:


bootstrap.yml – All configuration is required before application boots up, so instead of application.yml we will have bootstrap.yml file. This has application name (needs to exactly same as defined on git) and config-server URL.















Below is code for spring-boot application with one rest endpoint.




Now start the application and enter in browser




Cheers - Happy Learning 
Ketan Gote




Comments

Popular posts from this blog

Redis Basic CRUD

We have seen how to setup on your linux machine here , now we will see how to perform basic CRUD operations using Spring Data & Redis server We will be creating a simple application that would persist an employee information into redis database. You will be needing certain JARs like jedis.jar, spring-data-redis.jar etc details of which you can download and view at https://github.com/meta-magic/RedisCRUDexample.git  First of all we will be creating the Employee entity, plz note that we are using the Serializable interface which automatically mapps the objects against the key. Employee.java import java.io.Serializable ; public class Employee implements Serializable { private static final long serialVersionUID = - 8243145429438016231L ; public enum Gender { Male , Female } private String id; private String name; private Gender gender; private int age; public String getId () { return id; } public void setId ( String

Function Point Analysis : ISO/IEC 20926:2009

This blog focuses on explaining the Function Point calculations. Software Sizing Background Function Point Rules for Counting FP Deep Dive - Function Point Analysis Case Study General Software Characteristics Details History - Measurement Methodologies Lines of Code (Oldest) Use case based Software Sizing IPFUG Function Point Analysis (ISO) Need for Software Sizing. Estimation and Budgeting Phasing Development Work Prioritization of Work Monitoring the Progress Bidding for Projects Allocating Testing Resources To measure and Manage Productivity Risk Assessment Software Asset Valuation CMMi Level 2 and 3 require that a valid sizing method be used. Software Sizing - Lines of Code The easiest and historically the most common method in Sizing Software project has been counting the number of lines of code and / or the number of screens. Advantages Automation of the counting process can be done Intuitive as the measurements are easily u

Redis Installation Steps

“ Redis is an in-memory key-value store known for its flexibility, performance, and wide language support” Inorder to install redis on your machine you need ubuntu 16.4 and a non-root user with sudo privileges to perform the administrative functions required for this process. Download and Extract the Source Code Create a tmp directory cd /tmp Download the latest stable version of Redis curl -O http://download.redis.io/redis-stable.tar.gz untar tar xzvf redis-stable.tar.gz Move into the Redis source directory structure that was just extracted cd redis-stable Build and Install Redis Now, we can compile the Redis binaries by typing make After the binaries are compiled, run the test suite to make sure everything was built correctly. You can do this by typing: make test This will typically take a few minutes to run. Once it is complete, you can install the binaries onto the system by typing: sudo