In a conventional architecture, if any configuration information changes, we usually need to log on to the server and manually modify the configuration for the configuration take effect. In a microservices architecture, the number of applications and nodes increases sharply due to the rapid growth of microservices. As a result, applications are published more and more frequently, making configuration changes more difficult. The common practice is to abstract the application configurations and place them in an external configuration center to automate the configuration changes. However, this type of native solution has serious dependency and high release delay problems.
Spring Cloud provides the Spring Cloud Config component to manage the configuration by default.
For the working mechanism of Spring Cloud Config, see the following diagram:
Unlike the conventional method of manually modifying configuration on production servers one by one, the method supported by Spring Cloud is much easier. If your configuration changes, you can modify the configuration in Git, and then use the Spring Cloud Config Server to dynamically distribute the configuration to each of the servers. The process is as follows:
Now, the configuration modification is finished.
The Spring Cloud Config component successfully solves the cumbersome O&M problems of static configuration in the configuration center. However, Spring Cloud Config still has the following drawbacks:
Alibaba Cloud Application Configuration Management Service (ACM), as a cloud implementation of Nacos, can optimize the preceding configuration management problems. With ACM, the configuration modification becomes extremely simple and efficient, as shown in the following diagram.
The entire process is divided into two steps:
ACM is fully compatible with Spring framework APIs, including Spring Framework, Spring Boot, and Spring Cloud. ACM for Spring Cloud, compared to Spring Cloud Config, has a number of benefits due to the simplified architecture:
Spring Cloud users can seamlessly migrate the configuration management of Spring Cloud applications to ACM by using the API provided by Spring Cloud Config. This greatly improves the configuration management agility of microservices applications running in the Spring Cloud framework. ACM has several additional useful features in comparison with Spring Cloud Config, such as security compliance assessment of cloud configuration, phased release of configuration, and rollback.
For Spring Cloud users who need to switch from Spring Cloud Config to Alibaba Cloud ACM, no additional changes to the business code is required. Spring Cloud’s @Value annotation is valid in ACM. Users only need to modify two compilation configuration files of the Spring Cloud application.
1. Modify the configuration file
Add the ACM connection address and authentication information in bootstrap.properties, as shown in the following example. Parameters such as endpoint, namespace, accessKey, and secretKey can be obtained directly on the ACM console.
After the spring.application.name and spring.cloud.nacos.config.file are specified, the configuration name on the ACM console is determined. In the preceding example, the configuration name is com.alibaba.nacos.example.properties.
2. Add the nacos starter dependency into pom
See the following snippet:
After completing the above two modifications, re-package and compile the Spring Cloud program to switch to ACM configuration management.
The /echo API returns the value of the dynamic configuration parameter configValue.
Package and run the following code snippet. Add the configuration on the corresponding ACM console. Set the corresponding configuration name DataID (in this case com.alibaba.nacos.example.properties), and click Publish.
Finally, run the curl command locally, assuming that the http monitoring port is 8080:
The following will be returned:
If the true value is returned the configuration is successful. For detailed program examples, see ACM official documentation.
Alibaba AI Achieves the World's Best Results for Two LiTS Challenge Tasks
2,599 posts | 762 followers
FollowAlibaba Clouder - March 26, 2019
Alibaba Clouder - July 26, 2019
Alibaba Clouder - September 7, 2020
Alibaba Developer - October 13, 2020
Alibaba Clouder - November 18, 2019
Alibaba Clouder - June 15, 2020
2,599 posts | 762 followers
FollowMarketplace is an online market for users to search and quickly use the software as image for Alibaba Cloud products.
Learn MoreBuild business monitoring capabilities with real time response based on frontend monitoring, application monitoring, and custom business monitoring capabilities
Learn MoreAlibaba Cloud Container Service for Kubernetes is a fully managed cloud container management service that supports native Kubernetes and integrates with other Alibaba Cloud products.
Learn MoreMore Posts by Alibaba Clouder