This is the 16th day of my participation in Gwen 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 focused on the implementation details of the Spring Cloud Config client and server.

The basic application of Spring Cloud Config consists of three main elements:

  • Configuring the Server
  • Configuring the Client
  • Configuration of the warehouse

When the Config client is started, the corresponding configuration information is pulled from the Config Server according to the configuration rules, and then the context of the Config Client is initialized. Dynamic refreshes of configurations and webHook applications for configuration refreshes have also been added.

Other functions such as pattern matching and repO, encryption and decryption of configuration warehouse, attribute overlay, SVN configuration (local) warehouse, security protection and other functions, this article will focus on the advanced functions at the beginning.

Let’s start with how to configure multiple REPOs for Config Server.

Configure multiple REPOs for config Server

In the previous example, we configured the git repo of config server as follows:

spring.cloud.config.server.git.uri: https://gitee.com/keets/Config-Repo.git
Copy the code

It also supports more complex requirements, matching patterns with profiles through the application name Application. The pattern format is a comma-separated list of wildcard {application}/{profile} names (where you may need to reference patterns that begin with wildcards).

The Pattern property in the REPo is an array, so you can use a YAML array to bind multiple Patterns. We need to do this when we want to run multiple profiles of the application. Spring Cloud will guess that when a pattern contains a profile that does not end with *, it implies that you actually want to match profiles that start with that pattern. This is normal; for example, we might need to run the Development profile locally while running the Cloud profile remotely.

By default, Config Server is only configured to clone remotely on the first request. Config Server can be set to clone from the remote repository at startup.

spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/spring-cloud-samples/config-repo
          repos:
			  simple: https://github.com/simple/config-repo          
            development:
              pattern:
                - '*/development'
                - '*/staging'
              uri: https://github.com/development/config-repo
            staging:
              pattern: staging*
              cloneOnStart: true
              uri: https://github.com/staging/config-repo
Copy the code

In the above configuration, repos is configured with multiple warehouses: simple, Development, and staging. The mode matching of multiple Repos can be explained through three different repos configuration methods.

  • Simple repository: The matching pattern issimple/*, meaning that only all profiles of the application named Simple are matched. The shortcut configuration method used in Simple can only be used to set the ADDRESSES of URIs. To set other information (such as credentials or modes), you must use the full format.
  • Development repository:*/staging["*/staging", "*/staging,*"]Short for an application that matches a profile at the beginning of staging. In the same way,*/developmentMatches all applications with profiles starting with Development.
  • Staging: Pattern corresponds tostaging*, staging repo matches all application names starting with staging. There are no profiles at all./ *The suffix is automatically added to any pattern that does not have a profile match. After the config Server function is enabled, clone the warehouse to the local PC.

summary

This article focuses on configuring multiple REPOs on the Spring Cloud Config Server, Config Server. We configure different environments and warehouses according to different environments, and can separate the production warehouse from the development test warehouse. In the following articles, we will continue to learn about the advanced applications of Spring Cloud Config.