RPC Project Guide

Create a shared interface and call parties in the order of API → Server → Client.

How the three projects collaborate

API defines interface contract, DTO and service path; Server implements the interface and exposes HTTP service; Client refers to the same API and calls Server through Feign. RPC for this set of templates is based on HTTP / OpenFeign.

EngineeringExample coordinatesrole
APIcom.example:demo-api:1.0.0-SNAPSHOTTo share interfaces and DTOs, first install them in the Maven repository
Servercom.example:demo-server:1.0.0-SNAPSHOTPort 8080, context /demo-server
Clientcom.example:demo-client:1.0.0-SNAPSHOTPort 8081, context /demo-client

Install the RPC template first

The source code contains three modules of RPC, but their release metadata in Maven Central has not been confirmed this time. Please install the entire template project from source code to the local warehouse instead of directly using the 1.0.3 version number of the ordinary template.

git clone https://github.com/lodsve/lodsve-maven-archetype.git
cd lodsve-maven-archetype
# The template source code baseline corresponding to this article.
git checkout d1450a5767509f1605ce9797a3ac2cd3e5758dae
./mvnw clean install
cd ..
export ARCHETYPE_VERSION=1.0.4-SNAPSHOT
# Set the Boot version confirmed by project selection.
: "${LODSVE_BOOT_VERSION:?Set LODSVE_BOOT_VERSION first}"

After the template is successfully built, execute the generation commands for each page in the following order.

Creation order

  1. Generate RPC API, build and install the shared API package.
  2. Generate RPC Server, referencing the API package.
  3. Generate RPC Client, referencing the same version of API.
  4. Align the service discovery configuration in Server and Client before initiating Server and Client verification calls.

Configurations that must be aligned

  • The basic packages of the three projects are unified as com.example.rpc in the example to avoid the generated Java import pointing to non-existent packages.
  • serverAppName=demo-server of the API corresponds to spring.application.name of the Server; serverContextPath=/demo-server corresponds to the Servlet context path of the Server.
  • Server and Client use the same apiGroupId, apiArtifactId, and apiVersion.
  • The Nacos Discovery address for the Server/Client template example is http://localhost:8888, which is not the universal default. Replace the address, account, namespace and group, and confirm that the selected dependency combination actually provides Nacos service discovery and Feign capabilities.

Validation boundaries

The template contains response data that demonstrates the Controller and memory constructs. The successful generation of the file only verifies scaffolding parameter substitution; API compilation, dependency compatibility, service registration and remote calling still need to be verified in the specific environment.

RPC template source code

Architecture diagram