代码之家  ›  专栏  ›  技术社区  ›  clo_jur

具有protobuf文件的grpc的典型组织

  •  2
  • clo_jur  · 技术社区  · 8 年前

    我使用gRPC在服务和protobuf序列化之间进行通信。我以前没有真正使用过RPC,我想知道什么是proto文件的最佳结构?目前,我在一个产品中拥有所有proto文件,布局示例如下:

    protos/
      identity/
        models/
          Member.proto
        MemberService.proto
      vault/
        models/
          Authentication.proto
          Session.proto
          HttpHeader.proto
        AuthenticationService.proto
    

    我认为我应该将模型与实际的服务定义分开,这样我就可以导入单个模型而不需要整个服务。

    然后,每个服务都有以下布局

    synatx "proto3";
    
    import "models/Session.proto"
    
    message GetRequest {
      uint64 member_id;
    }
    
    message GetResponse {
      Session session;
    }
    
    rpc AuthenticationService {
      get (GetRequest) returns (GetResponse);
    }
    

    import "../protos-gen/AuthenticationService.grpc.h Authentication.proto 模型

    1 回复  |  直到 7 年前
        1
  •  2
  •   Lin Du Correcter    7 年前

    通常,人们将服务定义放在消息原型旁边。只有当原型变得非常大时,人们才会将其分解,但即使这样也很罕见。