×
Community Blog How to Manage Cloud-Native Applications Configurations Using Alibaba Cloud Application Configuration Management Service

How to Manage Cloud-Native Applications Configurations Using Alibaba Cloud Application Configuration Management Service

This article explains how to manage cloud-native applications configurations using Alibaba Cloud Application Configuration Management.

By Wamala Emmanuel Nsubuga

What Is Application Configuration Management?

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.

Application Configuration Management Features

  • Core Functionalities: Creating, deleting, modifying, and querying configurations
  • Configuration Tags: Organizing configurations with tags helps you manage configurations more efficiently.
  • Supports Multiple Languages: Supports Java/CPP/Python/Shell/HTTP OpenAPI
  • One-Click Rollback: Reduces the risk of changing configurations
  • Change History: Makes everything auditable
  • Data Encryption: Enhances the security of sensitive data

Application Configuration Management Benefits

  • Configuration changes are applied to multiple applications simultaneously.
  • ACM encrypts configurations to secure the information.
  • ACM reduces the possibility of having several versions of a specific configuration file in different applications due to errors in updating the different application configurations.
  • ACM reduces the amount of duplicate work needed to update configurations for each application.
  • Configuration changes take immediate effect when using the ACM configuration listening API.
  • Auditing, version management, and debugging are easier because configuration changes and versions are recorded automatically.

How to Manage Cloud-Native Applications Configurations Using Alibaba Cloud Application Configuration Management Service

Activating ACM

You must activate the ACM service before using it. Go to the ACM product homepage and click Get it Free:

1

Select I agree with the ACM Agreement of Service and click Enable Now:
2

Creating a Configuration on ACM

Log on to the ACM console, select Configurations on the left-side navigation pane, and click Create in the upper-right corner:

3

Enter the following data on the Create Configuration page and click Publish:

4
5

Using the API to Listen for Configuration Changes

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:

6

Modifying Configuration Changes

On the configurations page of the ACM console, search for the configuration. In the Actions column, click Edit:

7
Change the configuration body on the Edit Configuration page and click Publish:

8
Verify the configuration changes are correct in the Content Comparison dialogue box and click Confirm Publishing:

9
A notification will be displayed:

10

Conclusion

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.

0 0 0
Share on

Alibaba Cloud Community

1,042 posts | 256 followers

You may also like

Comments

Alibaba Cloud Community

1,042 posts | 256 followers

Related Products