This topic explains how to create and dynamically adjust configuration values in ACM with an example.


  • You have Activate ACM.
  • JDK has been installed on the machine, and the environment variable JAVA_HOME has been set.

Background information

The business application “myapp.jar”  is deployed onto two production servers.  This application contains a configuration file  “app.cfg”, which consists of two configuration items: thread pool size and log level.  Now, you need to adjust the configuration of the application on these two servers simultaneously and refresh the state of the application dynamically. The scenario is shown in the following figure:

Configuration details are as follows:

## app.cfg ##

Step 1: Create configuration in ACM

  1. Log on to the .
  2. In the left-side navigation pane, select Configurations, and then click the + button in the upper-right corner.   The Create Configuration page is displayed.
  3. Enter the following on the page, and click Publish.
    • Data ID:
    • Group: myapp
    • Content:

     See the figure below:

Step 2: Create a Maven project

  1. Run the following command to create a Maven project, or download the sample project myapp.tar.
    For instructions on how to install and use Maven, see Maven documentation.
    mvn archetype:generate -DgroupId=com.acm.sample -DartifactId=myapp -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

    The created project structure is as follows:

     `--  src
        | -- main
        | '-- java
        | '-- com
        | '-- acm
        | '-- sample
        | '-- App. Java
        '-- test
            '-- java
                `-- com
                    `-- mycompany
                        `-- app
  2. Add the ACM Client Native API dependency to Pom.  
         <! -- Remove the following if logging implementation is available. -->
  3. Listens for configuration changes with an API.
    // -- App. Java
         package com.acm.sample;
         import java.util.Properties;
         public class App {
         Private Static Properties appcfg = new properties ();
         public static void initAndWatchConfig() {
             final String dataId = "";
             final String group = "myapp";
             final long timeoutInMills = 3000;
             // Copy the corresponding values from the "Namespace Management" in the console.
             Properties properties = new Properties();
             Properties. put ("endpoint", "$ endpoint ");
             Properties. put ("namespace", "$ namespace ");
             Properties. put ("accessKey", "$ accessKey ");
             Properties. put ("SecretsKey", "$ secretsKey ");
             // If it is an encrypted configuration, then add the following two lines for automatic decryption.
     //properties.put("openKMSFilter", true);
     //properties.put("regionId", "$regionId");
             // Start a use-once scenario to get the configuration values directly.
             try {
                 String configInfo = ConfigService.getConfig(dataId, group, timeoutInMills);
                 appCfg.load(new StringReader(configInfo));
             } catch (ConfigException e1) {
             } catch (IOException e) {
             // 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
         public static void refreshApp() {
             System.out.println("current thread pool size: " + appCfg.getProperty("threadPoolSize"));
             System.out.println("current log level: " + appCfg.getProperty("logLevel"));
         public static void main(String[] args) {
             // Make sure the main thread does not exit.
             while (true) {
                 try {
                 } catch (InterruptedException e) {

Step 3: Deploy and start the application

Copy the JAR package to one or two servers to deploy and then start the application.

The deployment can be performed by running the following command in shell:

${JAVA_HOME}/java -cp myapp.jar com.acm.sample.App
To run Java programs, install  JDKon the server and set the JAVA_HOME environment variable.

Step 4: Search and change the configuration in the ACM console

  1.  Log on to the ACM console.
  2. On the Configurations page, search for the configuration created in Step 1: Create configuration in ACM.
  3. Click Details in the Actions column. The Configuration Details page is displayed.
  4. On this page, change the configuration content to the following and click Publish.

    See the figure below:

Step 5: Verify results

After the configuration is released, we can see that the configuration changes are received simultaneously on both servers on which the application is deployed, and the following information is printed.

current thread pool size: 15
current log level: DEBUG


In this example, a configuration is created for the application “myapp” on ACM and the Native API of ACM is used in the program to listen for changes to this configuration. When we changed the configurations in ACM, Every server to which this application is deployed receives the changed configurations, and the application status changes accordingly.