When you host a locally developed Spring Cloud or Dubbo application on SAE, you can use the built-in service registry provided by SAE, or set up a self-managed Nacos instance for service registration and discovery. This topic describes how to configure Nacos-based service registration and discovery for your application in the SAE console.
Recommendations
If you have a large number of microservices applications, you can use one of the following types of service registries that are listed in descending order by recommendation level:
-
MSE Nacos registry
-
Self-managed service registry
-
SAE built-in service registry
SAE provides a built-in Nacos server that supports automatic addressing for Java microservices. You can configure it by using the Service Registration and Discovery feature of SAE.
Prerequisites
The yum command is installed.
Before you run the application, make sure that the access port of the Nacos service registry, such as port 8848, is added to a security group. For more information, see Add a security group rule.
Step 1: Configure the Nacos server
In this step, you install and start a self-managed Nacos instance. Nacos requires a Java environment. If you build and run Nacos from source code, you must also configure a Maven environment.
For instructions, see Nacos Quick Start. After Nacos is installed and started, it provides service registration and discovery. You must then specify the service registry on the application side. After the application runs, the system automatically performs service registration and discovery based on the specified service registry.
Step 2: Configure service registration and discovery in SAE
This topic describes only the key steps. For the complete procedure to create an application.
The entry point varies with your scenario:
Create an application
Log on to the SAE console. In the left-side navigation pane, choose Application Management > Application List. Select the target region and the target namespace, and then click Create Application.
On the Basic Information wizard page, configure the parameters and then click Next: Advanced Settings.
Modify a running application
After you redeploy an application, the application is restarted. To prevent unpredictable errors such as business interruptions, we recommend that you deploy applications during off-peak hours.
Log on to the SAE console. In the left-side navigation pane, choose Application Management > Application List. Select the target region and the target namespace, and then click the name of the target application.
On the Basic Information page of the target application, click Deploy Application.
Modify a stopped application
Log on to the SAE console. In the left-side navigation pane, choose Application Management > Application List. Select the target region and the target namespace, and then click the name of the target application.
On the Basic Information page of the target application, click Modify Application Configuration.
Use one of the following methods to connect to Nacos based on your requirements:
Method 1: Configure service registration and discovery
Find and expand the Service Registration and Discovery section, and set Nacos-based Registry Service and Discovery to Self-managed Registry (Nacos, ZK, etc.).
After you select Self-managed Registry (Nacos, ZK, etc.), you must manually configure the service registry address in your application and make sure that the application can connect to the service registry over the network.
Method 2: Configure startup parameters
When you use startup parameters, confirm the following items:
Make sure that the SAE network can communicate with the network of your self-managed Nacos instance.
Make sure that the
-Dand-XXparameters are not used alternately. Otherwise, the command may not take effect. The following example shows a startup command before and after modification:Before the modification:
java -Dalicloud.deployment.mode=EDAS_MANAGED -XX:+UseContainerSupport -XX:InitialRAMPercentage=70.0 -XX:MaxRAMPercentage=70.0 -XX:+UnlockExperimentalVMOptions -XX:+UseWisp2 -Dio.netty.transport.noNative=true -XX:+UseG1GC -Dspring.profiles.active=yace -Dnacos.use.endpoint.parsing.rule=false -Dnacos.use.cloud.namespace.parsing=false -jar /home/admin/app/xx-server.jarAfter the modification:
java -XX:+UseContainerSupport -XX:InitialRAMPercentage=70.0 -XX:MaxRAMPercentage=70.0 -XX:+UnlockExperimentalVMOptions -XX:+UseWisp2 -Dio.netty.transport.noNative=true -XX:+UseG1GC -Dspring.profiles.active=yace -Dnacos.use.endpoint.parsing.rule=false -Dnacos.use.cloud.namespace.parsing=false -jar /home/admin/app/xx-server.jar
The only difference is that the modified command removes the
-Dalicloud.deployment.mode=EDAS_MANAGEDparameter.As a best practice, deploy the application by using an image or a JAR package, and configure the
-Dnacos.use.endpoint.parsing.rule=falseand-Dnacos.use.cloud.namespace.parsing=falsestartup parameters.Important
The startup parameters must be placed before
-jar. Otherwise, your application may fail to use a registry other than the SAE built-in service registry.If you deploy the application by using an image, configure
-Dnacos.use.endpoint.parsing.rule=falseand-Dnacos.use.cloud.namespace.parsing=falsein the application startup command of the image file. For more information about how to create a Docker image, see Create an image.The following code shows an example:
RUN echo 'eval exec java -Dnacos.use.endpoint.parsing.rule=false -Dnacos.use.cloud.namespace.parsing=false -jar $CATALINA_OPTS /home/admin/app/hello-edas-0.0.1-SNAPSHOT.jar'> /home/admin/start.sh && chmod +x /home/admin/start.shIf you deploy the application by using a JAR package, go to the Startup Command Settings section in the console and enter
-Dnacos.use.endpoint.parsing.rule=false -Dnacos.use.cloud.namespace.parsing=falsein the Options Settings text box. For more information, see Set a startup command.