This is the 20th day of my participation in the Genwen Challenge

“Configuration center Spring Cloud Config in detail” series of articles updated, together in the road of technology progress! This series of articles will introduce Spring Cloud Config, which provides a distributed configuration center in Spring Cloud. In addition to the code to realize system functions, application services also need to connect resources and other applications. There are often a lot of data that need to be configured externally to adjust the behavior of applications, such as switching different databases and setting function switches. With the increase of microservices, the system needs to be scalable and extensible, in addition to managing the configuration data of a considerable number of service instances. In the application development stage, each service is autonomous, but in the production environment, it will bring great trouble to the operation and maintenance, especially the micro service scale is relatively large, configuration update is more troublesome. Therefore, the system needs to establish a unified configuration management center.

In previous articles, we mainly introduced symmetric encryption and decryption and asymmetric encryption and decryption for Spring Cloud Config advanced applications. This article continues with the Spring Cloud Config quick response failure and retry mechanism.

Quick response failure

In some cases, it may be more appropriate to let the service start up fail when the client cannot connect to Config Server. If this behavior is more appropriate, set up the launch configuration properties of spring. The cloud. Config. FailFast = true, the client will in the presence of abnormal termination.

Retry mechanism

When the client application is started, the Config Server may be unavailable due to network jitter and other problems. We can use the retry mechanism to keep trying. Of course, this is built on the above fast response failure to close the case, we need to add the following dependencies:

<dependency>
    <groupId>org.springframework.retry</groupId>
    <artifactId>spring-retry</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-aop</artifactId>
</dependency>
Copy the code

By default, spring-retry attempts are six times. The initial rollback interval is 1000ms, and the exponential multiplier of subsequent rollback is 1.1. We can customize these configurations:

spring:
  cloud:
    config:
      retry:
        max-attempts: 6
        multiplier: 1.1
        initial-interval: 1000
        max-interval: 2000
Copy the code

Summary of this series of articles

In the microservice architecture, the business units of each microservice are further refined, and the services are split, resulting in a large number of microservices. When so many need to test and production line, there could be multiple environments, such as integration testing, staging and production line environment, each environment configuration file will be different (such as the data source configuration, switch and routing rules, etc.) and, if not a centralized configuration management center, each environment configuration information updated will be very trouble, A lot of work can also easily lead to perceived mistakes.

Spring Cloud Config is based on Cloud storage of configuration information. It has centralization, version control, dynamic update support, platform independence, language independence and other features. Spring Cloud Config is still relatively easy to use and meets the needs of most companies.

The beauty of Spring Cloud Config is that its configuration is stored in Git, which naturally insulates configuration changes, permissions, versions, and so on. This design makes Spring Cloud Config simple overall, but it also introduces some inconveniences. The functions of Spring Cloud Config can be further added and enriched, such as: configuration interface, one interface to manage different environments and different cluster configurations; Example configuration monitoring, you can easily see which clients are currently using which configurations