The Application Configuration Management (ACM) package provides the ability to test the ACM SDK locally. Your application can obtain the configuration locally for testing without connecting remotely to the ACM cloud server.

Currently, the ACM package supports Mac, Linux, and Windows platforms, and JDK 1.8 and later. The following table lists the functions of the ACM cloud server and the ACM local server that is generated after the ACM package is installed locally.

Item ACM cloud server ACM local server
Configuration setting Supported Supported
Historical versions Supported Not supported
Configuration listening and query Supported Not supported
Push tracks Supported Not supported
Namespaces Supported Not supported

Deploy ACM

  1. Download the acm-server package from acm-server.tar.gz to a local directory.
  2. Decompress the downloaded package. The acm-server directory is generated under the current directory.
    tar xzvf acm-server.tar.gz
  3. Go to the acm-server directory, run the startup script, and run acm-server.
    cd acm-server/bin
    sudo sh catalina.sh run
  4. Browse to localhost:8080/diamond-server.

    The preceding logon page indicates that acm-server has been started.

Create a configuration in the ACM local console

  1. Enter localhost:8080/diamond-server in the browser.
  2. On the Configuration Management page, click Create Configuration.
  3. Enter the data ID, group ID, and content of the configuration to be created, and then click Publish to create this new configuration.

Query a configuration in the ACM local console

  1. On the Configuration Management page, enter the data ID and group ID to be queried, and click Search.
    Note If you enter only a data ID, all configurations with this data ID are displayed. If you do not enter any query conditions, all configurations are displayed.
  2. In the list of query results, find the target query result and click Details in the Actions column.
  3. In the Configuration Body field, view the configuration content.

Modify a configuration in the ACM local console

  1. In the list of query results, find the target query result and click Edit in the Actions column.
  2. In the Configuration Body field, modify the configuration content. Then click Publish.

Delete a configuration in the ACM local console

  1. In the list of query results, find the target query result and click Delete in the Actions column.
  2. In the dialog box that appears, click OK.

Test the ACM SDK

  1. Bind the acm.aliyun.com domain name.

    The ACM SDK uses the acm.aliyun.com domain name to connect to ACM. Therefore, you need to modify the hosts file and bind this domain name to the 127.0.0.1 local IP address so that the ACM SDK can access the ACM local server.

    vim /etc/hosts
    add  127.0.0.1 acm.aliyun.com
  2. Write a sample request for testing the ACM SDK.

    Enter the dataId and group of your newly created configuration in the ACM SDK. If the configuration can be obtained, the local test environment is successfully deployed.

    public class ACMTest {
     public static void main(String[] args) throws ConfigException, InterruptedException {
         //Initialize the configuration service. The console automatically obtains the following parameters by using the example code. The input parameters are the endpoint, namespace, accessKey, and secretKey. The secretKey is ACM-specific, instead of Alibaba Cloud secretKey.
         ConfigService.init("acm.aliyun.com", "", "", "");
         String content = ConfigService.getConfig("acm.test", "DEFAULT_GROUP", 6000);
         System.out.println(content);
         //Add a listener to the configuration during initialization so that a callback notification will be sent when the configuration is modified.
         ConfigService.addListener("acm.test", "DEFAULT_GROUP", new ConfigChangeListener() {
             public void receiveConfigInfo(String configInfo) {
                 //After the configuration is updated, the latest configuration value will be displayed.
                 //Do not set callback to block. Otherwise, the notification thread may be blocked.
                 System.out.println("Continuing");
             }
         });
         //Do not let the main thread sleep.
         Thread.sleep(1000);
     }
    }