Updated on 2024-08-14 GMT+08:00

Using Service Registry

The service center of the ServiceComb engine provides the service registry function that registers basic information, such as the application to which a microservice belongs, microservice name, microservice version, and listening address, with the service center when the microservice is started.

During microservice running, the basic information about other microservices can be queried through the service center. The registered information varies with microservice development frameworks. For example, the service contract information is registered in Java chassis. The registered basic information and the process of registering and discovering other microservices are the same for all microservice development frameworks.

This section describes how different microservice development frameworks use the service center and configure their own registry information, as well as the configuration items related to the interaction between microservices and the registry center. After a microservice is registered, you can use the ServiceComb catalog, instance list, and dependencies in CSE.

Spring Cloud

When Spring Cloud uses service registry, you need to add the following dependencies to the project:

<dependency> 
  <groupId>com.huaweicloud</groupId>  
  <artifactId>spring-cloud-starter-huawei-servicecomb-discovery</artifactId> 
</dependency>

If the dependencies have been directly or indirectly included in the project, you do not need to add them. Table 1 describes the configuration items of Spring Cloud. The values of these configuration items affect the basic information registered in the service center and the interaction between microservices and the service center, such as heartbeats. Information related to service registry needs to be configured in the bootstrap.yml file.

Table 1 Common configuration items of Spring Cloud

Item

Description

Default Value

Remarks

spring.cloud.servicecomb.discovery.appName

Application

default

-

spring.cloud.servicecomb.discovery.serviceName

Microservice name

-

If no service name exists, use spring.application.name.

spring.cloud.servicecomb.discovery.version

Microservice version

-

-

server.env

Environment

-

The value is the environment ID. Example value: production or development.

spring.cloud.servicecomb.discovery.enabled

Whether to enable service registry and discovery

true

-

spring.cloud.servicecomb.discovery.address

Registry center address

-

Use commas (,) to separate cluster addresses.

spring.cloud.servicecomb.discovery.watch

Whether to enable the watch mode

false

-

spring.cloud.servicecomb.discovery.healthCheckInterval

Interval for sending heartbeat messages, in seconds

15

Value range: 1 ≤ configuration item ≤ 600.

spring.cloud.servicecomb.discovery.datacenter.name

Data center name

-

-

spring.cloud.servicecomb.discovery.datacenter.region

Data center region

-

-

spring.cloud.servicecomb.discovery.datacenter.availableZone

AZ of the data center

-

-

spring.cloud.servicecomb.discovery.allowCrossApp

Whether cross-application calling is supported

false

Server configuration, indicating that clients in different applications are allowed to discover themselves.

Java Chassis

When Java chassis uses service registry, you need to add the following dependencies to the project:
<dependency>
  <groupId>org.apache.servicecomb</groupId>
  <artifactId>registry-service-center</artifactId>
</dependency>

If the dependencies have been directly or indirectly included in the project, you do not need to add them. Table 2 describes the configuration items of Java chassis. The values of these configuration items affect the basic information registered in the service center and the interaction between microservices and the service center, such as heartbeats.

Table 2 Common configuration items of Java chassis

Item

Description

Default Value

Remarks

servicecomb.service.application

Application

default

-

servicecomb.service.name

Microservice name

defaultMicroservice

-

servicecomb.service.version

Microservice version

1.0.0.0

-

servicecomb.service.environment

Environment

-

The value is the environment ID. Example value: production or development.

servicecomb.service.registry.address

Registry center address

http://127.0.0.1:30100

Use commas (,) to separate cluster addresses.

servicecomb.service.registry.instance.watch

Whether to enable the watch mode

true

-

servicecomb.service.registry.instance.healthCheck.interval

Interval for sending heartbeat messages, in seconds

30

-

servicecomb.service.registry.instance.healthCheck.times

Indicates the allowed number of heartbeat failures. If the heartbeat fails for the consecutive times+1 times, the instance is brought offline by the service center. That is, interval x (times + 1) determines the time when an instance is automatically deregistered. If the service center does not receive a heartbeat message for a long time, the service center deregisters the instance.

3

-

servicecomb.datacenter.name

Data center name

-

-

servicecomb.datacenter.region

Data center region

-

-

servicecomb.datacenter.availableZone

AZ of the data center

-

-

The instance address and listening address registered by Java chassis are related to the release address specified by servicecomb.service.publishAddress. The configuration items of the service listening address are servicecomb.rest.address and servicecomb.highway.address, which correspond to the listening addresses of the REST and highway transmission modes, respectively. Table 3 shows the relationship between the registered address, listening address, and release address.

Table 3 Effective rules of registered instance addresses

Listening Address

Release Address

Registered Instance Address

127.0.0.1

-

127.0.0.1

0.0.0.0

-

Set it to the IP address of a NIC. The wildcard address, loopback address, or broadcast address is not selected.

Specific IP address

-

Set it to the listening address.

*

Specific IP address

Set it to the release address.

*

"{NIC name}"

Specifies the IP address corresponding to the NIC name. Note that the IP address must be enclosed in quotation marks and brackets.