You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "DMwangnima (via GitHub)" <gi...@apache.org> on 2023/06/14 04:20:23 UTC

[GitHub] [dubbo-go] DMwangnima commented on issue #2263: Lightweight HTTP1&2 Protocol to avoid direct depend on grpc-go library.

DMwangnima commented on issue #2263:
URL: https://github.com/apache/dubbo-go/issues/2263#issuecomment-1590442905

   Temporary triple design documentation:
   #  Triple-go
   
   ## 设计目标
   
   1. 在完全兼容Grpc,保证与老应用正常通信的基础上,支持h1和h2下采用curl,浏览器等web方式直接访问服务,无需任何配置
   2. 剥除对grpc-go的依赖,使用net/http
   3. 保持 编写IDL文件->protoc编译自动生成stub代码->实现业务逻辑 的工作模式,stub代码结构与接口向Grpc靠近(暂定)
   
   ## 设计细节
   
   #### 组成
   
     Rest + Grpc,服务端在单端口上同时支持这两种协议,客户端由用户选择调用方式,默认为Grpc
   
   #### 协议区分
   
     统一进入ServeHTTP(responseWriter http.ResponseWriter, request *http.Request)后,
   
     POST/GET? + content-type: application/ -> Rest
   
     POST + content-type: application/grpc -> Grpc
   
   #### Rest
   
   1. 额外Header:  triple-timeout-ms, triple-version
   
   2. rpc错误信息: json编码的Error
   
      ```go
      type WireError struct {
         Code    Code                 `json:"code"`
         Message string               `json:"message,omitempty"`
         // google.golang.org/genproto/googleapis/rpc/errdetails
         Details []*ErrorDetail       `json:"details,omitempty"`
      }
      ```
   
   3. Triple Error Code与HTTP Code映射:
   
      ```go
      switch code {
      case CodeCanceled:
         return 408
      case CodeUnknown:
         return 500
      case CodeInvalidArgument:
         return 400
      case CodeDeadlineExceeded:
         return 408
      case CodeNotFound:
         return 404
      case CodeAlreadyExists:
         return 409
      case CodePermissionDenied:
         return 403
      case CodeResourceExhausted:
         return 429
      case CodeFailedPrecondition:
         return 412
      case CodeAborted:
         return 409
      case CodeOutOfRange:
         return 400
      case CodeUnimplemented:
         return 404
      case CodeInternal:
         return 500
      case CodeUnavailable:
         return 503
      case CodeDataLoss:
         return 500
      case CodeUnauthenticated:
         return 401
      ```
   
   4. GET query params(ignore)
   
      triple=v1 // 协议版本
   
      encoding=json //编码方式,等同于content-type
   
      message=... //编码后的请求参数,还需要经过base64序列化
   
      compression=gzip //压缩方式,等同于content-encoding
   
      
   
      eg:
   
      GET /buf.greet.v1.GreetService/Greet?triple=v1&encoding=json&msg=%7B%22name%22%3A%22Buf%22%7D HTTP/1.1
      Host: demo.connect.build
   
      < HTTP/1.1 200 OK
      < Content-Type: application/json
      <
      < {"greeting": "Hello, Buf!"}
   
   5. 只支持unary,不支持stream
   
   6. 对于具有幂等性的调用,才支持GET(ignore)
   
   #### Grpc
   
   1. 参照https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md进行实现,完全使用net/http
   2. 需要性能测试得出与grpc-go的具体差距
   3. 需要cross-test,triple client -> grpc-go server, grpc-go client -> triple server,可考虑新起一个项目保证triple本身足够轻量
   
   #### protoc-gen-triple-go
   
   1. 为了兼容dubbo-go,引入ClientImpl和ProviderBase
   
      对于用户端,var cli = new(ClientImpl);config.SetConsumerService(cli);config.Load()后直接使用cli即可
   
      对于服务端,用户编写的struct需要wrap一下ProviderBase
   
   2. 目前triple-go和protoc-gen-triple-go为泛型版本,需要考虑是否更改为非泛型版本。对于用户来说,除了版本升级问题,接口处的请求参数也需要NewRequest wrap一下。


-- 
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: notifications-unsubscribe@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org