Enterprise Distributed Application Service (EDAS) provides the general availability (GA) version of the Nacos registry. Applications developed in Nacos can use this shared registry of EDAS without code modification. You need only to deploy the applications to EDAS. This topic describes how to develop a pair of Spring Cloud sample microservice applications in an on-premises environment based on Nacos. The pair includes a service provider and a service consumer.
Background information
Microservice applications use registries to implement service registration and discovery. When you develop an application, you can select a registry based on your actual needs.
You can use Nacos that is described in this topic as a registry to implement service registration and discovery for your application. You can also use other types of registries, such as Eureka, ZooKeeper, and Consul that are user-created or managed in Microservice Engine (MSE). After you deploy your application to EDAS, you can use the application management, microservice governance, and cloud native Platform as a Service (PaaS) features of EDAS regardless of the registry type.
You can implement service registration and discovery for your application based on the instructions in this topic. You can also download the application demos: service-provider and service-consumer.
Preparations
Before you develop an application, make sure that you have completed the following operations:
- Download Maven and set the environment variables.
- Download the latest version of Nacos Server.
- Perform the following steps to start Nacos Server:
- Decompress the downloaded Nacos Server package.
- Go to the
nacos/bin
directory to start Nacos Server.- On Linux, UNIX, or macOS, run the
sh startup.sh -m standalone
command. - On Windows, double-click the
startup.cmd
file to run the file.
- On Linux, UNIX, or macOS, run the
Create a service provider
Create a provider application project in an on-premises environment, add dependencies, enable the service registration and discovery feature, and then specify Nacos Server as the registry.
Create a service consumer
This section describes the service registration feature and explains how Nacos Server works with RestTemplate and FeignClient.
Test the result in an on-premises environment
Initiate a call from the consumer to the provider in an on-premises environment and test the result.
- On Linux, UNIX, or macOS, run the following commands:
curl http://127.0.0.1:18082/echo-rest/rest-rest curl http://127.0.0.1:18082/echo-feign/feign-rest
- On Windows, enter http://127.0.0.1:18082/echo-rest/rest-rest and http://127.0.0.1:18082/echo-feign/feign-rest in the browser.
What to do next
After applications are developed, they can be deployed to EDAS. For more information, see Overview and Overview.
Configuration items for reference
Configuration item | Key | Default value | Description |
---|---|---|---|
Server address | spring.cloud.nacos.discovery.server-addr | None | The IP address and the port on which Nacos Server listens. |
Service name | spring.cloud.nacos.discovery.service | ${spring.application.name} | The name of the current service. |
Network interface controller (NIC) name | spring.cloud.nacos.discovery.network-interface | None | If no IP addresses are specified, the registered IP address is the IP address of the NIC. If this configuration item is not specified, the IP address of the first NIC is used by default. |
Registered IP address | spring.cloud.nacos.discovery.ip | None | This configuration item has the highest priority. |
Registered port | spring.cloud.nacos.discovery.port | -1 | No configurations are required by default. The system automatically detects the port. |
Namespace | spring.cloud.nacos.discovery.namespace | None | Namespaces are widely used to isolate resources in different environments. For example, you can use namespaces to isolate the resources, such as configurations and services, in the development, test, and production environments. |
Metadata | spring.cloud.nacos.discovery.metadata | None | This item must be configured in the Map format. You can specify metadata information that is related to the service based on your needs. |
Cluster | spring.cloud.nacos.discovery.cluster-name | DEFAULT | The name of the Nacos cluster. |
Endpoint | spring.cloud.nacos.discovery.endpoint | UTF-8 | The domain name of the service in the region. You can dynamically retrieve the server address by using this domain name. You do not need to specify this configuration item when you deploy the service to EDAS. |
Enable Ribbon integration | ribbon.nacos.enabled | true | Change the value only when you need. |
For more information about Spring Cloud Alibaba Nacos Discovery, see the open source version of Nacos Discovery.