What is Spring Cloud Config Server?
Spring Cloud Config Server is a tool that externalizes configuration for microservices, centralizing it in a single location. This server supports various backends for storing configuration, including Git, SVN, or even a local file system. It retrieves configuration from these sources and provides it to microservices dynamically. The Config-server store the Configurations(Application.properties) files of all microservices.
Spring Cloud Config Server is a tool that externalizes configuration for microservices, centralizing it in a single location. This server supports various backends for storing configuration, including Git, SVN, or even a local file system. It retrieves configuration from these sources and provides it to microservices dynamically. The Config-server store the Configurations(Application.properties) files of all microservices.
Key Benefits
- Centralized Configuration: Stores all configuration files in one repository for different environments like development and production.
- Dynamic Updates: Microservices can fetch and apply updated configurations without restarting.
- Environment Management: Serves environment-specific configurations, such as separate files for development and production.
Sample Configuration Flow
Development Steps- Centralized Storage: Configuration files are stored in GitHub with environment-specific profiles.
- Microservices Fetch Configurations: Microservices request their configurations from the Config Server based on their environment.
- Configuration Refresh: Microservices can automatically reload updated configurations without restarting.
- Configure Config-Server
- Create a Config Server: Set up a Spring Boot project with and add the necessary dependency.
- Import Config Server: Import config-server as module in IDE.
- Enable Config Server: Enable Config-Server by using this annotation @EnableConfigServer in main class.
- Registering with Eureka: Use Eureka to enable load balancing and fault tolerance for the Config Server and microservices.
- Create a GitHub Repo: Create a GitHub Repository to store configurations of all Microservices.
- Defactor Microservice to use Config-Server
- Refactor Microservices(Employee-Service & Department-Service) to use Config-Server: Microservices will get their own configuration from GitHub using Config-Server.
- Add Two Dependencies in Employee-Service POM.
- Create a Properties file in the GitHub repo for Employee-Service.
- Add Config-Server URL in the Application.properties file of Employee-Service.
- Move all information from the Application.properties file to GitHub
- Run and Verify from the Postman client
Configure Config-Server
1. Create a Config Server: Create a config-server with below Dependency from Spring Initializr.
4. Registering with Eureka: Follow the same steps to register as a Eureka Client, as done for the Service-Registry and API-Gateway.
- Config Server
- Eureka Discovery Client
- Spring Boot Actuator
2. Import Config Server: This is the same way to import in IDE like Service-Registry, API-Gateway. Just follow below steps from screenshot.
3. Enable Config-Server with @EnableConfigServer: Add @EnableConfigServer annotation in class level of main class of Config-Server.
Enable Config Server |
Follow the 3rd steps from here(API-Gateway Registered as Eureka Client)
After registered, Project won't run before setup GitHub Repository.
5. Make link Config-Server with GitHub Repo: Here have some steps to store Configurations of each Microservice in GitHub. Follow the below steps to store all microservice's configuration to GitHub.
Link Config-Server with GitHub Repo and Run project on 8888 port |
Defactor Microservice to use Config-Server
(Defactor Employee-Service to use Config)
Steps
- Add Two Dependencies in Employee-Service POM.
- Create a Properties file in the GitHub repo for Employee-Service.
- Add Config-Server URL in Application.properties file of Employee-Service.
- Move all information from Application.properties file to GitHub
- Run and Verify from the Postman client
- Add Two Dependencies
- Config Client
- Spring Boot Actuator
- Create Properties file in GitHub repo for Employee-Service: Properties file name must be same as Employee-Service name (employee-service.properties). This is not case-sensitive. So we can use lowercase.
- Add Config-Server URL in the Application.properties file of Employee-Service.
- Move all information from the Application.properties file to the GitHub employee-service.properties file.
Defactor for Department-Service: Do the same for remain/new microservices.
0 Comments