Spring Cloud - Part 3
This post will be dedicated to Centralized Configuration Management for Microservices architecture.
The Codebase is present at GITHUB
Spring-Cloud-Config: Spring Cloud Config provides us a Centralized way of managing configuration details or properties for different services.
Other services can refer to this service for managing their configuration.
The Starter Class looks like:
Within src/main/resources we have defines config folder and define two properties file:
1) auth-service.yml
2) auth-service-dev.yml
The first property file will be referred by AUTH-SERVICE when it was initialized in default profile, and the second one will be referred when initialized with dev-profile.
The relevant configuration looks like:
We have declared to the port for this service to be concrete as the other services whose properties are configured here will be using this service.
So for the AUTH-SERVICE to use this service, it should have the following details in the configuration:
I would like to bring one last topic here i.e. Multiple instance registration for a service so that we see the Load Balancer in Action.
To register multiple instances of a service we should have the following:
The service ID will be spring.application.name, but for multiple instance registration of the service, the instance ID needs to be different otherwise the last registered instance will overwrite the previous one and everytime we will be getting only one instance. The uniqueness of the service instance ID is being ensured with random.value property.
Here is the final snapshot of Eureka after all the services up and running :
The Codebase is present at GITHUB
So this is short about Spring Cloud Config.
The Codebase is present at GITHUB
Spring-Cloud-Config: Spring Cloud Config provides us a Centralized way of managing configuration details or properties for different services.
Other services can refer to this service for managing their configuration.
The Starter Class looks like:
@SpringBootApplication @EnableEurekaClient @EnableConfigServer public class ConfigStarter { public static void main(String[] args){ SpringApplication.run(ConfigStarter.class, args); } }We have defined configuration for our AUTH-SERVICE only. However we can define configuration properties for any number of services we like.
Within src/main/resources we have defines config folder and define two properties file:
1) auth-service.yml
2) auth-service-dev.yml
The first property file will be referred by AUTH-SERVICE when it was initialized in default profile, and the second one will be referred when initialized with dev-profile.
The relevant configuration looks like:
spring:See we told Spring Cloud Config to look into the classpath under folder config for the centralized configuration management.
  application:
   name: config-server
  profiles:
   active: native
  cloud:
   config:
    server:
     native:
      searchLocations: classpath:/config
We have declared to the port for this service to be concrete as the other services whose properties are configured here will be using this service.
So for the AUTH-SERVICE to use this service, it should have the following details in the configuration:
spring:Just refer to the config URI, which tells where to look at for the configurations.
  application:
   name: auth-service
  profiles:
   active: dev
  cloud:
   config:
   uri: http://localhost:5555/configservice
I would like to bring one last topic here i.e. Multiple instance registration for a service so that we see the Load Balancer in Action.
To register multiple instances of a service we should have the following:
instance:in the configuration. The noteworthy point here is the instance ID with which the service will be registered in Eureka.
  preferIpAddress: true
  leaseRenewalIntervalInSeconds: 10
  metadataMap:
   instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
The service ID will be spring.application.name, but for multiple instance registration of the service, the instance ID needs to be different otherwise the last registered instance will overwrite the previous one and everytime we will be getting only one instance. The uniqueness of the service instance ID is being ensured with random.value property.
Here is the final snapshot of Eureka after all the services up and running :
The Codebase is present at GITHUB
So this is short about Spring Cloud Config.
Comments
Post a Comment