A simple application showing how get Spring application properties from Consul KV Store and how to integrate Consul KV Store with Git/Gitlab repositories by using git2consul.
The properties used in this project are mapped in my spring-consul-config repository.
Consul is a service mesh solution providing a full featured control plane with service discovery, configuration, and segmentation functionality. Each of these features can be used individually as needed, or they can be used together to build a full service mesh.
Access Consul documentation for mor information.
git2consul takes one or many git repositories and mirrors them into Consul KVs. The goal is for organizations of any size to use git as the backing store, audit trail, and access control mechanism for configuration changes and Consul as the delivery mechanism.
Access git2consul project for mor information.
- Java 11
- Docker and Docker Compose
The project uses docker-compose to configure and run 2 services: consul and git2consul.
consul:
image: consul
container_name: consul
ports:
- "8500:8500"
volumes:
- ./config:/consul/config
Inside the config folder there a file named config.json, which is used to register our service in Consul service discovery:
{
"services": [
{
"id": "spring-consul-application",
"name": "spring-consul-application",
"tags": ["primary"],
"port": 8080
}
]
}
Access Consul Service Discovery documentation for more details.
git2consul:
image: cimpress/git2consul
depends_on:
- consul
container_name: git2consul
volumes:
- .:/config
command: --endpoint consul --config-file /config/git2consul.json
The file git2consul.json is used to inform the minimal configuration required by git2consul:
{
"version": "1.0",
"repos" : [
{
"url" : "https://github.com/GuilhermeFelipe616/spring-consul-config.git",
"name" : "config",
"branches" : ["master"],
"expand_keys": true,
"include_branch_name" : false,
"hooks": [{
"type" : "polling",
"interval" : "1"
}]
}
]
}
Access git2consul configuration section for more details.
- Clone the project;
- Open a bash window inside the project root folder;
- Run
docker-compose up
command; - Start the spring application;
Obs: Remember to start Docker before running
The properties can be consulted by requesting the REST API like below:
[GET] http://localhost:8080/spring-consul/name
[GET] http://localhost:8080/spring-consul/nick
[GET] http://localhost:8080/spring-consul/code