You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by GitBox <gi...@apache.org> on 2021/11/15 07:03:29 UTC

[GitHub] [incubator-brpc] KaneVV1 removed a comment on issue #1589: BRPC兼容GRPC stream

KaneVV1 removed a comment on issue #1589:
URL: https://github.com/apache/incubator-brpc/issues/1589#issuecomment-968592825


   > **Is your feature request related to a problem? (你需要的功能是否与某个问题有关?)**
   > 
   >   stream是rpc框架使用中的常用功能,虽然brpc有streaming rpc,但是兼容grpc stream能给框架的这部分功能带来更大的泛用性。   经过百度内部Service Mesh实践,出于定制化需求方向的考虑,我们希望在proxyless模式下,brpc能够直连istio,逐渐减弱对envoy的依赖。istio下发配置使用的是双向grpc stream,所以我们需要完成brpc兼容grpc stream的适配。  主要需求如下:   1、兼容grpc steam的同步/异步或订阅推送式的客户端;   2、一如既往简单便捷的客户端API,不希望定制protobuf插件。  后续事项:*服务端API设计、直达底层h2协议的性能调优
   > 
   > **Describe the solution you'd like (描述你期望的解决方法)**
   > 
   > 以grpc stream Demo的消息格式 https://github.com/grpc/grpc/blob/fd3bd70939fb4239639fbd26143ec416366e4157/examples/python/data_transmission/demo.proto 为例,可以通过以下API来对grpc stream服务端进行访问。
   > 
   > ```c++
   > using namespace brpc;
   > demo::Request req;
   > demo::Response res;
   > Controller cntl;
   > 
   > demo::GRPCDemo_Stub stub(&channel);
   > 
   > // 客户端流模式(在一次调用中, 客户端可以多次向服务器传输数据, 但是服务器只能返回一次响应)
   > // rpc ClientStreamingMethod (stream Request) returns (Response);
   > auto writer = CreateStreamVisitor<demo::Request, GrpcWriter>(
   >     &demo::GRPCDemo_Stub::ClientStreamingMethod, &stub, &res, &cntl);
   > writer->Write(req);
   > writer->WritesDone(); 
   > writer->Finish();
   > 
   > // 服务端流模式(在一次调用中, 客户端只能一次向服务器传输数据, 但是服务器可以多次返回响应)
   > // rpc ServerStreamingMethod (Request) returns (stream Response);
   > auto reader = CreateStreamVisitor<demo::Response, GrpcReader>(
   >     &demo::GRPCDemo_Stub::ServerStreamingMethod, &stub, &req, &cntl);
   > while (reader->Read(&res)) {
   >     std::cout << ... << std::endl;
   > }
   > reader->Finish();
   > 
   > // 双向流模式 (在一次调用中, 客户端和服务器都可以向对方多次收发数据)
   > // rpc BidirectionalStreamingMethod (stream Request) returns (stream Response);
   > auto stream = CreateStreamVisitor<demo::Request, demo::Response, GrpcReaderWriter>(
   >     &demo::GRPCDemo_Stub::BidirectionalStreamingMethod, &stub, &cntl);
   > std::thread writer([stream]() {
   >     for (int i = 0; i < 3; ++i) {
   >         stream->Write(req);
   >     }
   >     stream->WritesDone();
   > });
   > while (stream->Read(&res)) {
   >     std::cout << ... << std::endl;
   > }
   > writer.join();
   > stream->Finish();
   > ```
   > 
   > 具体设计 TBD
   > 
   > **Describe alternatives you've considered (描述你想到的折衷方案)** 简单地直接引入GRPC依赖
   > 
   > **Additional context/screenshots (更多上下文/截图)**
   
   
   
   > 接口好像有点多。 WritesDone和Finish是什么关系?可不可以合为一个。 writer->Finish()和stream->Finisher()又是什么关系? 没发送完毕,业务要中途退出是要如何处理(writer/reader端都可能发生)? 本身rpc接口中的done这里要如何处理? 这个case并没有看到。 能已echo为例子写一个实际的包含错误处理的例子么。
   
   已更新case
   1、2 最好不要合一个,WritesDone用来保证发送端数据完整性,Finish来关闭整个流;
   3、done还未考虑


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org