When you deploy a locally developed Spring Cloud or Dubbo application to Serverless App Engine (SAE), you can use the built-in SAE service registry or a service registry hosted by Microservices Engine (MSE). This topic describes how to configure Nacos-based service registration and discovery for an application in the SAE console.
Prerequisites
-
A virtual private cloud (VPC) has been created and is available. For more information, see Create and manage a virtual private cloud.
-
Before you run the application, add the access port for the Nacos service registry (for example, 8848) to a security group. For more information, see Add a security group rule.
-
You have created an MSE Nacos engine and a namespace for the instance.
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
For more information, see MSE Nacos and open-source Nacos.
Limitations
For more information about the limitations of using an MSE Nacos engine, see Application of MSE Nacos SDKs and restricted versions of Nacos SDKs.
Entry points
The entry point varies depending on the scenario.
Create application
-
Log on to the SAE console. In the navigation pane on the left, choose Applications > Applications. Select the target region and namespace, and then click Create Application.
-
After you configure the parameters on the Basic Information page, click Next: Advanced Settings.
Modify 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 navigation pane on the left, choose Applications > Applications. Select the target region and namespace, and then click the name of your target application.
-
On the Basic Information page of the application, click Deploy Application.
Modify stopped application
-
Log on to the SAE console. In the navigation pane on the left, choose Applications > Applications. Select the target region and namespace, and then click the name of your target application.
-
On the Basic Information page of the application, click Modify Application Configuration.
Configure service registration and discovery
Find and expand the Service Registration and Discovery section. Set Nacos-based Registry Service and Discovery to MSE Nacos Professional Edition, and then select your MSE Nacos Instance and the corresponding Namespace.
Verify the results
To verify the deployment, on the application's Basic Information page, click the Instances tab. In the Actions column of the instance list, click Webshell and run verification commands in the Webshell window. For more information, see Use Webshell to diagnose applications.
-
Verify that the service is successfully registered.
curl -X GET 'http://192.168.XX.XX:8848/nacos/v1/ns/instance/list?serviceName=service-provider'
-
service-provider: the service name. -
192.168.XX.XX:8848: the IP address and port of the host where Nacos is running. Replace192.168.XX.XXwith the internal endpoint of your MSE Nacos engine. To obtain the internal endpoint, log on to the MSE console, click your target instance on the Instances page, and find the endpoint on the instance's Basic Information page.
The following output indicates that the service is successfully registered:
[/home/admin]$ curl -X GET 'http://mse-xxx-nacos-ans.mse.aliyuncs.com:8848/nacos/v1/ns/instance/list?serviceName=service-provider'
{"name":"DEFAULT_GROUP@@service-provider","groupName":"DEFAULT_GROUP","clusters":"","cacheMillis":10000,"hosts":[],"lastRefTime":1679984302840,"checksum":"","allIPs":false,"reachProtectionThreshold":false,"hitWeightProtection":false,"valid":true,"dom":"service-provider"} [/home/admin]$
-
Verify that the end-to-end access path for the microservice application works.
Run one of the following commands. 127.0.0.1:18082 is the IP address and access port of the host where the provider and consumer applications are running.
curl http://127.0.0.1:18082/echo-rest/{your-custom-variable}curl http://127.0.0.1:18082/echo-feign/{your-custom-variable}
A response of 192.168.0.222:hello indicates that the consumer application successfully called the provider application, confirming the microservice access path is working correctly.
[/home/admin]$ curl http://127.0.0.1:18082/echo-rest/hello
192.168.0.222:hello
[/home/admin]$