jmorgan0825 / SpringConsulDemo

This project demonstrates using Spring Cloud Consul for service discovery and the Consul KV Store for Spring Cloud Config. The project also demonstrates: loading Consul KV Store via Git2Consul, client-side load balancing using Ribbon, and a very simple example of Feign.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Project Objectives

This is a sample project to demonstrate Spring Cloud Config and Service Discovery with Consul. The project demonstrates how to load Consul KV Store from a Git Repository using Git2Consul. In addition, the project demonstrates a simple Feign client, Ribbon client-side load-balancing, and dynamic property refreshing.

I could only get the project to work correctly when the following property was set to yaml or properties despite the documentation calling for the property to be set with files.
spring.cloud.consul.config.format = yaml | properties

Remaining Objectives

  • Integrate Vault to store and resolve secrets
  • Refine the local development process (bypass bootstrap)
  • Include Zuul | Cloud Gateway into this project
  • Include Hystrix into this project
  • Connect Git2Consul to a private repository. How will it be secure?

Running this project

  1. Start Docker Container for Consul (runs on port 8500)
    docker-compose up
  2. Initialize Vault see below
  3. Run Application
    VAULT_APP_TOKEN=app_token SPRING_PROFILES_ACTIVE=mypillar,holding ./start.sh
    Or without Spring Profiles
    ./gradlew bootRun

Consul Key Value (KV) Structure

/ config / application / data
/ config / application-[spring-profile] / data
/ config / [microservice-name] / data
/ config / [microservice-name]-[spring-profile] / data

The application key: /config/application/data is considered global to all applications.
The application key: /config/application-[spring-profile]/data is considered global to all applications with the specified spring profile.
Consul Requires that YAML is suffixed by 'data' key to work properly. The configuration above assumes that the key values are all YAML.

Useful Project Links

Resources

Cloud Config Requirements

https://bitbucket.org/bettercloud/bettercloud-properties/src/03363ff028ab906fb2d349127b8dc230d2cd2a0d/config/?at=master

#once you disable bootstrap then service discovery is disabled hence no feign @Loadbalanced annotated endpoint will fail #Also any name-resolved rest templates will not work. We would need to make more dynamic configuration to support disabling bootstrap.

#Stackoverflow #https://stackoverflow.com/questions/38251693/correct-way-to-load-values-properties-from-spring-cloud-consul

https://github.com/JorgeHernandezRamirez/SpringCloudConsul https://github.com/spring-cloud/spring-cloud-consul/blob/master/docs/src/main/asciidoc/spring-cloud-consul.adoc

http://cloud.spring.io/spring-cloud-consul/multi/multi_spring-cloud-consul-config.html http://cloud.spring.io/spring-cloud-consul/multi/multi_spring-cloud-consul-discovery.html

Initialize Vault

$ export VAULT_ADDRESS=http://127.0.0.1:8200
$ ./tools/unseal_vault.sh # copy app token from output
$ export VAULT_APP_TOKEN=token

About

This project demonstrates using Spring Cloud Consul for service discovery and the Consul KV Store for Spring Cloud Config. The project also demonstrates: loading Consul KV Store via Git2Consul, client-side load balancing using Ribbon, and a very simple example of Feign.


Languages

Language:Java 76.6%Language:Shell 21.1%Language:HCL 2.3%