Spring Cloud Config principle
We push the configuration file to the remote repository through Git for version control. When the version changes, the remote repository pushes the message to the Config Server through webhook mechanism, and the Config Server sends the modification notification to the message bus. Then all Config clients are refreshed. Very clever use of Git for version control of configuration file changes.
Consul Config’s FILES mechanism
public enum Format {
/**
* Indicates that the configuration specified in consul is of type native key values.
*/
KEY_VALUE,
/**
* Indicates that the configuration specified in consul is of property style i.e.,
* value of the consul key would be a list of key=value pairs separated by new lines.
*/
PROPERTIES,
/**
* Indicates that the configuration specified in consul is of YAML style i.e., value
* of the consul key would be YAML format
*/
YAML,
/**
* Indicates that the configuration specified in consul uses keys as files.
* This is useful for tools like git2consul.
*/
FILES,
}
Copy the code
Consul provides key/value, YAML and properties, which can be easily configured using the management console of Consule Config. For FILES, like Cloud Config, Git is used for version control. Consul is only used for configuration distribution and change notification. Git native Consul does not support Git to do Consul, you need to use the Consul community provides another project git2Consul is very easy to download and install. Let’s focus on the git2consul.json initialization script
{
"version":"1.0"."local_store": "Local warehouse backup Address"."logger": {"name":"git2consul"."streams":[
{
"level":"trace"."type":"rotating-file"."path":"Log Generation path /git2consul.log"}},"repos":[
{
"name":"pig-config"."url":"Remote warehouse address"."include_branch_name" : true// Whether the branch information is included in the request"branches": ["dev"]."hooks":[
{
"type" : "polling"// Update policy is periodically refreshed"interval" : "1" //1分钟
}
]
}
]
}
Copy the code
Specify the above script at startup
./git2consul --config-file git2consul.json
Copy the code
Bootstrap. Yml configuration
spring:
application:
name: pig-auth
cloud:
consul:
host: localhost
port: 8500
config:
enabled: true
format: FILES
watch:
enabled: true
prefix: ${spring.application}/${spring.profiles.active}
profiles:
active: dev
Copy the code
OK is ready to use git2Consul to synchronize your configuration files.
Configuration details
See above for an example of my profile.
FILES mechanism is similar to Spring Cloud Config loading. Application. yml will be shared by all microservice modules, and the corresponding application-name.yml will be loaded by the corresponding microservice.
conclusion
- With integration Consul Config has achieved the same functionality as Spring Cloud Config, there is not much difference in how Spring Cloud Microservices use profiles.
- The real-time refresh mechanism is no different from the key-value mode mentioned in Consul Microservice configuration Center Experience. Git2consul not only supports WebHook push, but also polling pull, similar to some of the Apollo configuration Center features
-
- About PIG: Based on Spring Cloud, oAuth2.0 development platform based on Vue before and after separation, support account, SMS, SSO and other logins, provide supporting video development tutorials