By Wamala Emmanuel Nsubuga
Alibaba Cloud Application Configuration Management (ACM) is a service that allows centralized management of application configurations. For example, if you have multiple applications using the same configuration file or multiple instances of the same application, you can create one configuration file that pushes/distributes to all applications or application instances. In addition, ACM offers several functions, such as configuration push, configuration modification, historical version management, gray release, and configuration modification audit.
You must activate the ACM service before using it. Go to the ACM product homepage and click Get it Free:
Select I agree with the ACM Agreement of Service and click Enable Now:
Log on to the ACM console, select Configurations on the left-side navigation pane, and click Create in the upper-right corner:
Enter the following data on the Create Configuration page and click Publish:
Run the following command to create a sample project:
mvn archetype:generate -DgroupId=com.acm.sample -DartifactId=myapp -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Note: You must install JDK on the server and set the environment variable JAVA_HOME to run Java programs.
Add the ACM client native API dependencies in the pom.xml file:
<dependency>
<groupId>com.alibaba.edas.acm</groupId>
<artifactId>acm-sdk</artifactId>
<version>1.0.8</version>
</dependency>
<! -- Remove the following if logging implementation is available. -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.7</version>
</dependency>
</dependencies>
Add the raven-assembly-plugin packaging plug-in to the pom.xml file:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<finalName>myapp</finalName>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>com.acm.sample.App</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
Listen for configuration changes with the API:
//-- App.java
package com.acm.sample;
import java.io.IOException;
import java.io.StringReader;
import java.util.Properties;
import com.alibaba.edas.acm.listener.ConfigChangeListener;
import com.alibaba.edas.acm.ConfigService;
import com.alibaba.edas.acm.exception.ConfigException;
public class App {
private static Properties appCfg = new Properties();
public static void initAndWatchConfig() {
final String dataId = "com.acm.myapp.app.cfg";
final String group = "myapp";
final long timeoutInMills = 3000;
// Copy the corresponding values from the namespace page of the console.
Properties properties = new Properties();
properties.put("endpoint", "$endpoint");
properties.put("namespace", "$namespace");
properties.put("accessKey", "$accessKey");
properties.put("secretKey", "$secretKey");
// If it is an encrypted configuration, then add the following two lines for automatic decryption.
// properties.put("openKMSFilter", true);
// properties.put("regionId", "$regionId");
ConfigService.init(properties);
// Get configuration body directly.
try {
String configInfo = ConfigService.getConfig(dataId, group, timeoutInMills);
appCfg.load(new StringReader(configInfo));
} catch (ConfigException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Listen for configuration changes to get the latest values:
ConfigService.addListener(dataId, group, new ConfigChangeListener() {
public void receiveConfigInfo(String configInfo) {
try {
appCfg.load(new StringReader(configInfo));
} catch (Exception e) {
// process exception
}
refreshApp();
}
});
}
public static void refreshApp() {
System.out.println("current thread pool size: " + appCfg.getProperty("threadPoolSize"));
System.out.println("current log level: " + appCfg.getProperty("logLevel"));
System.out.println("");
}
public static void main(String[] args) {
initAndWatchConfig();
// Make sure the main thread does not exit.
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
}
}
Note: The user variables in the code, such as $endpoint, $namespace, and $accesskey, can be found on the namespace page of the ACM console, as shown in the following figure:
On the configurations page of the ACM console, search for the configuration. In the Actions column, click Edit:
Change the configuration body on the Edit Configuration page and click Publish:
Verify the configuration changes are correct in the Content Comparison dialogue box and click Confirm Publishing:
A notification will be displayed:
Alibaba Cloud Application Configuration Management (ACM) simplifies application configuration management with security, centralization (single source of truth), and versioning in one place. This promotes stable and available infrastructure and reduces time spent performing repetitive operations.
Identify and Analyze Images in Real-Time Using Alibaba Cloud Image Search
How to Set up Alibaba Cloud ApsaraDB for MongoDB for Your NoSQL Database Requirements
1,029 posts | 252 followers
FollowAlibaba Clouder - February 20, 2021
Alibaba Cloud Native Community - April 19, 2023
Alibaba Cloud Native Community - March 21, 2024
Alibaba Cloud New Products - June 11, 2020
Alibaba Cloud Native Community - November 11, 2022
Alibaba Clouder - February 14, 2020
1,029 posts | 252 followers
FollowAccelerate and secure the development, deployment, and management of containerized applications cost-effectively.
Learn MoreA configuration audit service that provides configuration history of enterprise resources in Alibaba Cloud and audits the compliance of resource configurations.
Learn MoreOrganize and manage your resources in a hierarchical manner by using resource directories, folders, accounts, and resource groups.
Learn MoreAlibaba Cloud Function Compute is a fully-managed event-driven compute service. It allows you to focus on writing and uploading code without the need to manage infrastructure such as servers.
Learn MoreMore Posts by Alibaba Cloud Community