gRPC / Protobuf interface versioning

前端 未结 3 1510
故里飘歌
故里飘歌 2021-01-01 20:24

Let\'s say we use gRCP/Protobuf to connect many application. Those application are developped and released at their own team, with their own speed. Over time there will be d

3条回答
  •  我在风中等你
    2021-01-01 21:23

    If you are using protocol buffers version 2, you can use the default values to implement this. Protocol buffers 3 has removed support for default values so this answer doesn't work there.

    In the .proto file defining your interface, have something like:

    message MyLoginMessage
    {
        ... normal login fields ...
    
        // Increment this number when you make new releases
        // of this .proto.
        optional int32 protocol_version [default=55];
    }
    

    This way any client will automatically include the version number taken from the .proto.

    Edit: Ah, just noticed the proto3 tag.. so I guess this answer is not useful to you after all.

提交回复
热议问题