Example code is part of tRPC-Java
repo. Clone and change directory to tRPC-Java
.
$ git clone https://github.com/trpc-group/trpc-java.git
$ cd trpc-java
The detailed example codes can be found in the trpc-demo
directory, as follows:
trpc-demo
├── trpc-java-demo # The directory for the basic example codes.
│ └──src/main/java/com/tencent/trpc/demo/example # The detailed example codes path.
│ ├── config # An example based on code configuration.
│ ├── yaml # An example based on YAML configuration files.
│ └── stream # An example of streaming functionality.
└── trpc-spring-demo # The directory for the example based on Spring Boot.
├── trpc-spring-client-demo # The client-side example based on Spring Boot.
└── trpc-spring-server-demo # The server-side example based on Spring Boot.
This document only demonstrates how to execute the example codes using the command line. If you are
using an IDE, you can directly import the tRPC-Java
repository and execute the corresponding
classes within the IDE.
To install tRPC-Java
and its dependencies locally, execute the following command:
$ mvn -Dmaven.test.skip=true clean install
Please compile tRPC-Java through
mvn -Dmaven.test.skip=true clean install
. If you want to run unit tests, you need to use JDK 8.
To run the server-side example codes, you can execute the following command:
$ mvn exec:java -pl :trpc-java-demo -Dexec.cleanupDaemonThreads=false -Dexec.mainClass=com.tencent.trpc.demo.example.config.ServerTest
Correct, when you run the server-side example codes, you should see the normal startup information
in the console. The server will run in the foreground, and if you want to stop the server, you can
press Ctrl-C
to terminate the process.
To execute the following command, open a new terminal and navigate to the tRPC-Java
directory.
Make sure that the server is already running before executing the command:
$ mvn exec:java -pl :trpc-java-demo -Dexec.cleanupDaemonThreads=false -Dexec.mainClass=com.tencent.trpc.demo.example.config.ClientTest
Correct, when you execute the client-side code, you should see the information indicating successful communication between the client and the server. Once the communication is completed, the client will terminate gracefully. You can observe the logs or any output in the console to verify the successful interaction between the client and server.
If you want to update the codes and re-execute it, you can navigate to the following directory and modify the corresponding codes:
src/main/java/com/tencent/trpc/demo/example/config
src/main/java/com/tencent/trpc/demo/example/server
After updating the codes, you can execute the following command to recompile it:
$ mvn -pl :trpc-java-demo clean compile
Once the codes are successfully compiled, you can proceed to execute the server-side example codes
by following the instructions mentioned earlier in the Run the Server-Side Example Codes
section.
- Read Basic Tutorial to get deeper into
tRPC-Java
.