Spring Cloud Config is horizontally scalable centralized configuration service for distributed systems. It uses a pluggable repository layer that currently supports local storage, Git, and Subversion.
In this project, I use native profile
, which simply loads config files from the local classpath. You can see shared
directory in Config service resources. Now, when Notification-service requests it's configuration, Config service responses with shared/notification-service.yml
and shared/application.yml
(which is shared between all client applications).
Just build Spring Boot application with spring-cloud-starter-config
dependency, autoconfiguration will do the rest.
Now you don't need any embedded properties in your application. Just provide bootstrap.yml
with application name and Config service url:
spring:
application:
name: notification-service
cloud:
config:
uri: http://config:8888
fail-fast: true
For example, EmailService bean was annotated with @RefreshScope
. That means, you can change e-mail text and subject without rebuild and restart Notification service application.
First, change required properties in Config server. Then, perform refresh request to Notification service:
curl -H "Authorization: Bearer #token#" -XPOST http://127.0.0.1:8000/notifications/refresh
Also, you could use Repository webhooks to automate this process
- There are some limitations for dynamic refresh though.
@RefreshScope
doesn't work with@Configuration
classes and doesn't affect@Scheduled
methods fail-fast
property means that Spring Boot application will fail startup immediately, if it cannot connect to the Config Service.- There are significant security notes below
For more information please refer to the main repository afermon/PiggyMetrics-Kubernetes
- Forked from sqshq/PiggyMetrics