YPP-RPC is a lightweight RPC framework based on Springboot implemented with native Java socket interface.
- Support synchronous remote calls
- Springboot integration
- Microservices friendly
- Use Protobuf encoding
- Persistent connection and more connection control
- Timeout and retry mechanism
- Error handling
- Graceful Termination
- Easy mock Test
- Gradle plugin code generation
✨ Your can find the example under
examples/demo
directory.
application | required version |
---|---|
JDK | 21 or later |
Gradle(Gradle wrapper) | 8.6 or later |
protoc | 26.0 or later |
💡Legacy JDK 8 support is also available. While The Gradle and protoc version should be the same as the above.
In this case, please use Springboot 2.X along with the
jdk8
suffix version of the Gradle pluginio.github.paopaoyue.ypp-rpc-generator
.
-
Create a new Springboot project You can create a new Springboot project by using the Spring Initializr.
❗Springboot version should be 3.3.0 or later, java version should be 21 or later. -
Add the following to your
build.gradle
file:
plugins {
id 'io.github.paopaoyue.ypp-rpc-generator' version '0.1.2' // or 0.1.2-jdk8 for java 8
}
rpcGenerator {
serviceName = 'demo-service'
serviceShortAlias = 'demo' // optional - default to serviceName
protoRepoPath = 'idl' // optional - default to 'idl' directory from the project root
}
- Run
gradlew generateIdl
to generate the idl files and modify the idl files to define your service. - Run
gradlew generateRpc
to generate the rpc files. - Configure the service endpoints in your `application.properties file:
mesh.rpc.server-enabled=true
mesh.rpc.server-service.name=demo-service
mesh.rpc.server-service.host=localhost
mesh.rpc.server-service.port=8080
mesh.rpc.client-enabled=true
mesh.rpc.client-services[0].name=demo-service
mesh.rpc.client-services[0].host=localhost
mesh.rpc.client-services[0].port=8080
- Modify the generated
RpcService
class to implement your service logic.
@RpcService(serviceName = "demo-service")
public class DemoService implements IDemoService {
@Override
public DemoProto.EchoResponse echo(DemoProto.EchoRequest request) {
return DemoProto.EchoResponse.newBuilder().setText(request.getText()).build();
}
}
- Run your Springboot application with
gradlew bootRun
and you are ready to go!
@Component
public static class DemoRunner {
@Autowired
private IDemoCaller demoCaller;
public void run() {
var response = demoCaller.echo(DemoProto.EchoRequest.newBuilder().setText("hello world").build(), new CallOption());
System.out.println(response.getText()); // should print "hello world"
}
}
The framework has provided @MockRpcService
and @MockRpcCaller
annotations so that the user can use Mockito library to mock the service as well as the caller in their unit-test or integration test.
@SpringBootTest
class DemoApplicationTests {
@Autowired
IDemoCaller demoCaller;
@Test
void MockTest() {
var response = demoCaller.echo(DemoProto.EchoRequest.newBuilder().setText("hello world").build(), new CallOption());
assertThat(response.getText()).isEqualTo("noop!");
}
@TestConfiguration
public static class TestConfig {
@MockRpcService(serviceName = "demo-service")
public IDemoService mockDemoService() {
IDemoService service = mock(DemoService.class);
when(service.echo(any())).thenAnswer(invocation -> {
DemoProto.EchoRequest request = invocation.getArgument(0);
return DemoProto.EchoResponse.newBuilder().setText("noop!").build();
});
return service;
}
}
}
- Basic RPC framework
- Gradle plugin for code generation
- Mesh Proxy for service discovery & load balancing in Kubernetes
- Better Observability
The benchmark is done by running the same service echo logic on ypp-rpc and grpc with 10 concurrent threads and each sends 10k requests.