Solon

grpc-solon-plugin

<dependency>
    <groupId>org.noear</groupId>
    <artifactId>grpc-solon-plugin</artifactId>
</dependency>

1、描述

分布式扩展插件。基于 grpc 适配的 rpc 插件。

2、配置示例

# 服务端申明
server.grpc:
  port: 9081
  name: demo-grpc

# 客户端申明(或者使用 solon cloud config 服务)
solon.cloud.local:
  discovery:
    service:
      demo-grpc:
        - "grpc://localhost:9081"

3、代码应用

  • 服务端(实现接口服务)
@GrpcService
public class HelloImpl extends HelloHttpGrpc.HelloHttpImplBase{
    @Override
    public void sayHello(HelloHttpRequest request, StreamObserver<HelloHttpResponse> responseObserver) {
        String requestMsg = request.getMsg();
        String responseMsg = "hello " + requestMsg;
        HelloHttpResponse helloHttpResponse = HelloHttpResponse.newBuilder().setMsg(responseMsg).build();
        responseObserver.onNext(helloHttpResponse);
        responseObserver.onCompleted();
    }
}
  • 客户端应用
@Controller
public class TestController {

    @GrpcClient("demo-grpc")
    HelloHttpGrpc.HelloHttpBlockingStub helloHttp;

    @Mapping("/grpc/")
    public String test() {
        HelloHttpRequest request = HelloHttpRequest.newBuilder().setMsg("test").build();

        return helloHttp.sayHello(request).getMsg();
    }
}

4、代码演示

https://gitee.com/noear/solon-examples/tree/main/7.Solon-Remoting-Rpc/demo7013-rpc_grpc