tencent cloud

Service Registry and Governance

gRPC-Java Integration

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 2026-05-07 18:12:22

Scenarios

This document demonstrates the full process of a gRPC-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 JDK and Maven installed and can access the Maven Central Repository.
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 Instance List page under Service Management Center, click the drop-down list in the upper-left corner of the page 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. Spring Cloud applications access using the gRPC port (8091):


5. Modify the registry center IP address in the demo.
5.1 In the downloaded demo source code directory, locate the two files respectively: \\grpc-java-polaris-examples\\quickstart-example\\provider\\src\\main\\resources\\polaris.yml and \\grpc-java-polaris-examples\\quickstart-example\\consumer\\src\\main\\resources\\polaris.yml.
5.2 Adding the Microservices Engine PolarisMesh IP address to the project configuration file (taking \\grpc-java-polaris-examples\\quickstart-example\\provider\\src\\main\\resources\\polaris.yml as an example).
global:
serverConnector:
addresses:
- 10.0.4.6:8091
6. Compile the source code into an executable program.
6.1 Under the root directory of the quickstart-example source code, open a command prompt and execute the command `mvn clean package` to package and compile the project.
6.2 After successful compilation, two binary packages are generated as shown in the following table.
Software Package Directory
Software Package Name
Description
\\grpc-java-polaris-examples\\quickstart-example\\provider\\target
quickstart-provider-${version}.jar
Service Provider
\\grpc-java-polaris-examples\\quickstart-example\\consumer\\target
quickstart-consumer-${version}.jar
Service Consumer
7. Deploy the provider and consumer microservices applications. Choose one deployment method based on your actual business needs from VM deployment and containerized deployment.
7.1 VM deployment
Upload the Jar package to the Cloud Virtual Machine (CVM) instance.
Run the start command to launch:
nohup java -Djava.security.egd=file:/dev/./urandom -jar [jar package name] &
7.2 Containerized deployment
Write the dockerfile to build the image. Refer to:
FROM java:8
ADD quickstart-provider-${version}-SNAPSHOT.jar /root/app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/root/app.jar"]
Deploy and run the image via TKE.
8. Verify the deployment results.
8.1 Go to the Micro PolarisMesh instance page mentioned earlier.
8.2 Choose Service Management > Service List to view the number of instances for the EchoServerGRPCJava microservice:
If the number of instances is not zero, it indicates that the microservices engine has been successfully connected.
If the number of instances is 0 or the EchoServerGRPCJava service name cannot be found, it indicates that the microservice application failed to connect to the microservice engine.


8.3 Invoke the consumer's HTTP interface: Execute the HTTP call, where ${app.port} is replaced with the consumer's listening port (default: 40041), and ${add.address} is replaced with the IP address exposed by the consumer.
curl -L -X GET 'http://${add.address}:${app.port}/polaris/grpc/quickstart/consumer?value="hello-polaris'
Expected return value: hello-polaris


도움말 및 지원

문제 해결에 도움이 되었나요?

피드백