All Products
Search
Document Center

Microservices Engine:Migrate applications from Application Configuration Management to MSE Nacos instances

最終更新日:Aug 08, 2023

Application Configuration Management has entered the deprecated state, and all data on Application Configuration Management will be deleted. We recommend that you migrate application configurations from Application Configuration Management to MSE Nacos instances at the earliest opportunity. MSE Nacos instances provide better performance stability and more features. This topic describes how to export configurations from the Application Configuration Management console and import the exported configurations to the MSE console.

Important

After Application Configuration Management reaches end of support, you cannot create or edit configurations in the Application Configuration Management console. Service-level agreement (SLA) is no longer guaranteed for API operations on Application Configuration Management after Application Configuration Management reaches end of support. Therefore, we recommend that you migrate the configurations at the earliest opportunity.

Step 1: Export application configurations to your MSE Nacos instance

  1. Log on to the MSE buy page with an Alibaba Cloud account and purchase a Nacos instance.

    We recommend that you purchase an MSE Nacos Professional Edition instance. MSE Nacos Professional Edition instances support Nacos 2.0, which supports configuration authentication and encryption and provides higher availability. For more information about how to select the number of vCPUs, memory, and number of nodes for an MSE Nacos Professional Edition instance, see Estimate the capabilities of Microservices Registry instances. If you want to purchase a public bandwidth for your Nacos instance, you can estimate the required public bandwidth based on a unit conversion. You can perform a unit conversion by using the following formula: Change frequency (unit: count/s) × Number of configurations × Configuration size (unit: KB).

  2. Export the configurations that you want to migrate from the Application Configuration Management console.

    1. Log on to the Application Configuration Management console.

    2. On the Configurations page, select the required configuration, and click Export in the lower part of the page. In the message that appears, click Export.

    3. Store the exported configuration file.

  3. Import the exported configuration file to the MSE console.

    1. Log on to the MSE console.

    2. In the left-side navigation pane, choose Microservices Registry > Instances.

    3. On the Instances page, click the ID of the Nacos instance that you purchased.

    4. In the left-side navigation pane, choose Configurations > Configurations.

    5. On the Configurations page, click Import Configurations.

    6. In the Import Configurations dialog box, select an option from the Same Configuration drop-down list, and click Upload File in Configuration File to upload the configuration file that is exported from the Application Configuration Management console. Then, click OK.

Step 2: Replace application business parameters

Select an appropriate method to replace the application business parameters based on the type of your application.

Spring Cloud Alibaba applications

If your application is a Spring Cloud Alibaba application, modify the bootstrap.properties configuration file of your application.

Replace

spring.cloud.nacos.config.endpoint=${Public or internal endpoint of Application Configuration Management}

With

spring.cloud.nacos.config.server-addr=${Public or internal endpoint of your MSE Nacos instance}

Specify the ID of a namespace in your MSE Nacos instance in the following configuration:

spring.cloud.nacos.config.namespace =${ID of a namespace in your MSE Nacos instance}

For more information about the sample demo, see acm2nacos-spring-cloud-example.

You can use the following method to check whether your application is a Spring Cloud Alibaba application:

If the following dependency is found in your pom.xml file, your application is a Spring Cloud Alibaba application.

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
Important

  • Only MSE Nacos 2.0.3 or later allows you to migrate configurations of Spring Cloud Alibaba applications to MSE Nacos instances. If your MSE Nacos version is 2.0.2 or earlier, you must upgrade the Nacos version in the MSE console. The upgrade process takes about 5 to 6 minutes.

  • To ensure high availability of an instance, configure at least three nodes for the instance.

  • You can obtain the public or internal endpoint of your MSE Nacos instance from the Basic Information page of the instance.

  • If you use the default namespace, the namespace does not have an ID. In this case, you can leave the namespace ID empty. If your destination namespace has an ID, you can obtain the namespace ID from the Namespace page of your MSE Nacos instance in the MSE console.

If you want to access the MSE Nacos instance over the Internet, you must add the public IP address of your client to the public IP address whitelist of your MSE Nacos instance to ensure connectivity.

Note

If no IP addresses or CIDR blocks are added to the public IP address whitelist of your MSE Nacos instance, all public IP addresses can be used to access your MSE Nacos instance.

Java applications

  • If ACM-Java-SDK is used, the following dependency exists in your pom.xml file.

    <dependency>
        <groupId>com.alibaba.edas.acm</groupId>
        <artifactId>acm-sdk</artifactId>
    </dependency>

    In this case, you can directly add the following parameter to the JVM runtime parameters and redeploy your application to complete the migration.

    -DDIAMOND.SERVER.IPS=${Public or internal endpoint of your MSE Nacos instance}

    Modify the namespace information in the code.

    properties.put("namespace", "{namespaceId}");

  • If you want to use the Nacos client instead of the Application Configuration Management client after the migration, follow the subsequent instructions.

  • If Nacos-Java-SDK is used, the following dependency exists in your pom.xml file:

<dependency>
  <groupId>com.alibaba.nacos</groupId>
  <artifactId>nacos-client</artifactId>
</dependency>

In this case, you can set ${} in the following code to the registered endpoint of your MSE Nacos instance, set {namespaceId} to the namespace ID of your MSE Nacos instance, and then redeploy your application to complete the migration. If the default namespace is used, leave {namespaceId} empty.

properties.put("serverAddr", ${Public or internal endpoint of your MSE Nacos instance});
properties.put("namespace", "{namespaceId}");

When you start your application, add the following parameter to complete the migration.

 -Dnacos.cache.data.init.snapshot=false
Note

For more information about the sample demo for using Nacos-Java-SDK to migrate configurations of Java applications, see acm2nacos-java-example. For more information about the sample demo for Nacos-Java-SDK, see Java SDK.

Nacos Spring Boot applications

If your application is a Nacos Spring Boot application, modify the application.properties configuration file of your application.

Replace

nacos.config.endpoint=${Public or internal endpoint of Application Configuration Management}

With

nacos.config.server-addr=${Public or internal endpoint of your MSE Nacos instance}

Specify the ID of a namespace in your MSE Nacos instance in the following configuration:

nacos.config.namespace=${ID of a namespace in your MSE Nacos instance}

Golang applications

Note

Before you call the operation, you must configure environment variables and obtain access credentials from the environment variables. The environment variables of the AccessKey ID and AccessKey secret for MSE Nacos instances are MSE_AK and MSE_SK respectively.

  • If ACM-golang-SDK is used, you must set ${endpoint} to the registered endpoint of your MSE Nacos instance.

    clientConfig := constant.ClientConfig{
            Endpoint:       ${endpoint} + ":8080",
            NamespaceId:    namespaceId,
            AccessKey:      MSE_AK,
            SecretKey:      MSE_SK,
            TimeoutMs:      5 * 1000,
            ListenInterval: 30 * 1000,
        }
  • If Nacos-golang-SDK is used, you must set ${serverAddr} to the registered endpoint of your MSE Nacos instance.

    sc := []constant.ServerConfig{
        {
        IpAddr: "${serverAddr}",
        Port:   8848,
        },
    }
Note

For more information about the sample demo for Nacos-golang-SDK, see nacos-sdk-go.

Python applications

  • If ACM-Python-SDK is used, you must set ${endpoint} to the registered endpoint of your MSE Nacos instance and ${namespace_id} to the namespace ID of your MSE Nacos instance.

    ENDPOINT = "${endpoint}"
    NAMESPACE = "${namespace_id}"
    c = acm.ACMClient(ENDPOINT, NAMESPACE, AK, SK)
  • If Nacos-Python-SDK is used, you must set ${server_address} to the registered endpoint of your MSE Nacos instance and ${namespace_id} to the namespace ID of your MSE Nacos instance.

    SERVER_ADDRESSES = "${server_address}"
    NAMESPACE = "${namespace_id}"
    client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE)

Node.js applications

  • If ACM-Nodejs-SDK is used, you must set ${endpoint} to the registered endpoint of your MSE Nacos instance and ${namespace_id} to the namespace ID of your MSE Nacos instance.

    // for find address mode
    const configClient = new NacosConfigClient({
      endpoint: '${endpoint}',
      namespace: '${namespace_id}',
      accessKey: 'MSE_AK',
      secretKey: 'MSE_SK',
      requestTimeout: 6000,
    });
  • If Nacos-Nodejs-SDK is used, you must set ${server_address} to the registered endpoint of your MSE Nacos instance and ${namespace_id} to the namespace ID of your MSE Nacos instance.

    const configClient = new NacosConfigClient({
      serverAddr: '${server_address}',
      namespace: '${namespace_id}',
      accessKey: 'MSE_AK',
      secretKey: 'MSE_SK',
      requestTimeout: 6000,
    });

C# applications

Set ${server_address} to the registered endpoint of your MSE Nacos instance and namespace_id to the namespace ID of your MSE Nacos instance.

{
  "NacosConfig": {
    "Listeners": [
      {
        "Optional": false,
        "DataId": "common",
        "Group": "DEFAULT_GROUP"
      },
      {
        "Optional": false,
        "DataId": "demo",
        "Group": "DEFAULT_GROUP"
      }
    ],
    "Namespace": "namespace_id",  // Please set the value of Namespace ID !!!!!!!!
    "ServerAddresses": [ "http://${server_address}:8848/" ],
    "UserName": "test2",
    "Password": "123456",
    "AccessKey": "MSE_AK",
    "SecretKey": "MSE_SK",
    "EndPoint": "acm.aliyun.com",
    "ConfigFilterAssemblies": ["YouPrefix.AssemblyName"],
    "ConfigFilterExtInfo": "some ext infomation"
  }
}

C++ applications

  • If ACM-CPP-SDK is used, you must set ${endpoint} to the registered endpoint of your MSE Nacos instance and $namespace_id to the namespace ID of your MSE Nacos instance.

    // Initialize configuration service and the console will retrieve the following parameters through the sample code.
     ACM::init("${endpoint}","$namespace_id","$accessKey","$secretKey");
  • If Nacos-CPP-SDK is used, you must set ${server_address} to the registered endpoint of your MSE Nacos instance.

    Properties props;
    props[PropertyKeyConst::SERVER_ADDR] = "${serverAddr}:8848";//Server address

Step 3 (Optional): Grant permissions to RAM users after the migration

If you use the configuration authentication feature to grant permissions to a specified RAM user, you must replace the authorization script and grant permissions to the RAM user again after your applications are migrated to the MSE Nacos instance.

  1. Log on to the Resource Access Management (RAM) console.

  2. In the left-side navigation pane, choose Permissions > Policies.

  3. In the upper-left corner of the Policies page, click Create Policy.

  4. On the Create Policy page, click the JSON tab.

  5. Use your on-premises script to replace the script in the code editor.

    Sample script to be replaced:

    {
        "Version": "1",
        "Statement": [
            {
                "Action": [
                    "acms:R"
                ],
                "Resource": "*:*:*:*:cfg/1ca01ca0-11b0-1e01-0df1-d1010101bc10/DEFAULT_GROUP/com.alibaba.acm.test",
                "Effect": "Allow"
            }
        ]
    }
  • Replace read permissions

    Replace

    "Action": [
                    "acms:R"
                ]

    With

    "Action": [
                    "mse:List*",
                    "mse:Query*",
                    "mse:Get*"
                ]
  • Replace write permissions

    Replace

    "Action": [
                    "acms:W"
                ]

    With

    "Action": [
                    "mse:Create*",
                    "mse:Update*",
                    "mse:Delete*"
                ]
  • Replace resource information

    Replace

    "Resource": "*:*:*:*:cfg/{acm_namespace_id}/{group_id}/{data_id}"

    With

    "Resource": "acs:mse:*:*:instance/{instance_id}/{mse_namespace_id}/{group_id}/{data_id}"
    Note

    Parameter description:

    • {acm_namespace_id}: the namespace ID of Application Configuration Management.

    • {instance_id}: the ID of your MSE Nacos instance.

    • {mse_namespace_id}: the namespace ID of your MSE Nacos instance.

    • {group_id}: the group ID.

    • {data_id}: the data ID.

If {group_id} or {data_id} is not required for authorization, you can delete the parameter.

  • If only {instance_id} and {mse_namespace_id} are required for authorization, replace the resource information with the following content:

    "Resource": "acs:mse:*:*:instance/{instance_id}/{mse_namespace_id}"
  • If only {instance_id}, {mse_namespace_id}, and {group_id} are required for authorization, replace the resource information with the following content:

    "Resource": "acs:mse:*:*:instance/{instance_id}/{mse_namespace_id}/{group_id}"

After the replacement is complete, grant the permissions that are specified in the script to the RAM user.

The permissions that are granted to the RAM user take effect 5 to 10 seconds after the re-authorization operation is performed.

Step 4: Redeploy and start your application

Redeploy your application. After the deployment is successful, the entire migration process is complete.