tencent cloud

Service Registry and Governance

Nearby Access

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 2026-05-07 18:12:22

Scenarios

This document demonstrates the full process of a Java application accessing the PolarisMesh governance center hosted by the microservice engine through a demo, helping you quickly understand how to use the nearby routing capability of PolarisMesh.

Prerequisite

The PolarisMesh has been created. For details, see Creating a PolarisMesh Governance Center.
Download the Github demo source code to your local machine and extract it.
The local build environment has the Java environment installed and can access Github.
Based on your business needs, resources for business deployment have been prepared. You can choose either virtual machine deployment or containerized deployment.
VM deployment The CVM instance has been created. For details, see Creating a CVM Instance.
Containerized deployment The TKE container cluster has been created. For details, see Creating a TKE Cluster.

Operation Steps

1. Log in to the TSE console.
2. On the polarismesh page under PolarisMesh, click the drop-down list in the upper left corner and select the target region.
3. Click the "ID" of the target engine to go to the basic information page.
4. View the IP address. The Java application accesses using the gRPC port (8091): 
5. Modify the registry center IP address in the demo:
In the downloaded demo source code directory, locate the quickstart-example-provider/src/main/resources/polaris.yml and quickstart-example-consumer/src/main/resources/polaris.yml files respectively.
Add the Microservices Engine PolarisMesh IP address and nearby routing configurations to the project configuration file (taking quickstart-example-provider/src/main/resources/polaris.yml as an example).
Obtain the region information of the SDK through environment variables
Obtain the SDK's Region Information via TencentCloud API
Obtain the current region information of CVM/container POD through Tencent Cloud API.
export ZONE=$(curl http://metadata.tencentyun.com/latest/meta-data/placement/region)
export CAMPUS=$(curl http://metadata.tencentyun.com/latest/meta-data/placement/zone)
Modify the polaris.yaml file.
global:
serverConnector:
addresses:
# Set the Polaris server access address
- 10.0.4.6:8091
# Set parameters related to service invocation
consumer:
serviceRouter:
plugin:
# Set the nearby routing plugin configuration
nearbyBasedRouter:
# Description: The minimum matching level for nearby routing must be explicitly set
# Scope: zone (Tencent Cloud region information, eg: ap-guangzhou), campus (Tencent Cloud AZ, eg: ap-guangzhou-3)
matchLevel: campus
global:
serverConnector:
addresses:
# Set the Polaris server access address
- 10.0.4.6:8091
# Set the way for the SDK to obtain its own geographic location information
location:
providers:
# Set the SDK to obtain region information by invoking an http interface
- type: remoteHttp
options:
zone: http://metadata.tencentyun.com/latest/meta-data/placement/region
campus: http://metadata.tencentyun.com/latest/meta-data/placement/zone
# Set parameters related to service invocation
consumer:
serviceRouter:
plugin:
# Set the nearby routing plugin configuration
nearbyBasedRouter:
# Description: The minimum matching level for nearby routing must be explicitly set
# Scope: zone (Tencent Cloud region information, eg: ap-guangzhou), campus (Tencent Cloud AZ, eg: ap-guangzhou-3)
matchLevel: campus
6. Deploy the provider and consumer microservices applications. For details, see Polaris-Java Demo deployment.
7. Verify the deployment results.
Go to the PolarisMesh instance page of the microservices engine mentioned earlier.
Choose Registry > Service List to view the number of instances for the microservice EchoServerJava.
If the number of instances is not zero, it indicates that the microservices engine has been successfully connected. Also, confirm the Tencent Cloud IP address location information of the instances.
If the number of instances is 0 or the EchoServerJava service name cannot be found, it indicates that the microservice application failed to connect to the microservice engine.


Enable nearby routing for EchoServerJava.


Invoke the HTTP interface of the consumer, executing the HTTP call by replacing ${app.port} with the listening port of the consumer (default: 16011), and ${add.address} with the exposed IP address of the consumer.
curl -L -X GET 'http://${add.address}:${app.port}/echo?value=hello_world'

# Expected to return service provider instance information in the same Tencent Cloud AZ as the consumer
Expected return value: "echo: hello_world, from: ${target instance port}, location: ${instance geographical location information}";


Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan