Basic use of SpringCloud's Config

Config overview

In a distributed environment, many services need to be deployed in clusters, which means that these services must provide the same service, so their configuration files must be the same; so extract a configuration file center, so that it can be pulled from a center Take the configuration file, so as to ensure that all configurations are the same; when modifying, only one place needs to be modified.

​ SpringCloud **Config provides centralized external configuration support for microservices in the microservice architecture; **Configuration server provides a centralized external configuration for all environments of different microservice applications; Config is divided into server and The client has two parts.

Config server:
Also known as the configuration center, it is an independent microservice application that is used to connect to the configuration server and provide clients with access interfaces such as obtaining configuration residences, encrypting, and decrypting residences.

Config client:
It manages application resources and business-related configuration content through a designated configuration center, and obtains and loads configuration information from the configuration center at startup.

Configure the server:
By default, git is used to store the configuration residence, which is helpful for version management of the environment configuration, and the configuration content can be easily managed and accessed through the git client tool.

Server creation:

Step 1: pom file

        <!--config server-side dependencies-->

Step 2: Add the annotation **@EnableConfigServer** to the startup class

package com.mmy;

//marked as config server
public class ConfigServerApplication {

    public static void main(String[] args) {, args);

Step 3: Configuration File

#The service name of the profile center
#The port of the configuration file center -- generally 8888 8889

#--------------------Associated configuration with git ------------------------- ----------------------

#The url address of the remote repository of the configuration file on gitee***
#Configuration file on gitee The directory path where the configuration file is stored in the remote repository***
#Username for logging in to gitee***
#Password to log in to gitee***
#Cache the configuration file in the remote repository of the configuration file on gitee to a local location***

Client build:

Step 1: pom file

		<!--config client-side dependencies-->

Step 2: Configuration File

#config client service name
#config client port

#---The config client pulls the configuration of the configuration file from the configuration center (config server)---

#The url address of the configuration center (config server)

#The rules for reading configuration files are:
#/{label}/{name}-{profile}.properties or /{label}/{name}-{profile}.yml
#label is the name of the branch where the configuration file is located, e.g. master branch
#name is the prefix of the configuration file name, e.g.
#profile is the environment for the profile name, e.g.

Solve dirty reads:

​ When the configuration file in git is modified, the data read by the client is still the data before the modification, and there is dirty reading;

Solution: use the Bus message bus to solve

Tags: Java Spring Spring Cloud

Posted by maliskoleather on Sun, 11 Sep 2022 23:25:24 +0530