8000 GitHub - PaoPaoYue/mesh: A lightweight RPC framework based on Springboot implemented with native Java socket interface.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
/ mesh Public

A lightweight RPC framework based on Springboot implemented with native Java socket interface.

Notifications You must be signed in to change notification settings

PaoPaoYue/mesh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YPP-RPC

Maven Central
YPP-RPC is a lightweight RPC framework based on Springboot implemented with native Java socket interface.

Features

  • 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

Quick Start

✨ Your can find the example under examples/demo directory.

Prerequisites

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 plugin io.github.paopaoyue.ypp-rpc-generator.

  1. 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.

  2. 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
}
  1. Run gradlew generateIdl to generate the idl files and modify the idl files to define your service.
  2. Run gradlew generateRpc to generate the rpc files.
  3. 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
  1. 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();
        }
    }
  1. 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"
        }
    }

Mock Test

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;
        }
    }
}

Roadmap

  • Basic RPC framework
  • Gradle plugin for code generation
  • Mesh Proxy for service discovery & load balancing in Kubernetes
  • Better Observability

Benchmark

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. benchmark

5BA7

About

A lightweight RPC framework based on Springboot implemented with native Java socket interface.

Resources

Stars

Watchers

Forks

Packages

No packages published
0