检测 client/server 版本不匹配的常用方法是什么
What is the common way to detect a client/server version mismatch
我们正在对远程系统上的 运行 我们的硬件实施 client/server 应用程序。
为此,我们使用 GRPC、protobuf v3。
当我们修改 .proto
文件并在不更新服务器的情况下重新编译客户端时,我们收到一条带有模糊消息的异常:
Exception was thrown by handler.
使用 GRPC,检测 client/server 版本不匹配的常用方法是什么?
编辑:修改示例
例如我们改变这个(消息参数的特定类型):
service RpcAcquisitionCard {
...
rpc SetNumericalControlOscillator(RpcNcoConfiguration)
...
}
message RpcNco {
RpcDeviceIdentifier deviceId = 1;
core.protobuf.RpcFrequency nco1 = 2;
core.protobuf.RpcFrequency nco2 = 3;
}
至此(消息参数的通用类型)
service RpcAcquisitionCard {
...
rpc SetNumericalControlOscillator(RpcCommandParameter)
...
}
message RpcCommandParameter {
RpcDeviceIdentifier deviceId = 1;
google.protobuf.Any parameter = 2;
}
message RpcNco {
core.protobuf.RpcFrequency nco1 = 1;
core.protobuf.RpcFrequency nco2 = 2;
}
其中 RpcCommandParameter.parameter
字段是 RpcNco
。
使用protobuf时推荐阅读Language Guide.
https://developers.google.com/protocol-buffers/docs/proto3#updating 与您的场景特别相关:
Fields can be removed, as long as the tag number is not used again in
your updated message type. You may want to rename the field instead,
perhaps adding the prefix "OBSOLETE_", or make the tag reserved, so
that future users of your .proto can't accidentally reuse the number.
那是你做错的地方。而不是改变:
message RpcNco {
RpcDeviceIdentifier deviceId = 1;
core.protobuf.RpcFrequency nco1 = 2;
core.protobuf.RpcFrequency nco2 = 3;
}
至:
message RpcNco {
core.protobuf.RpcFrequency nco1 = 1;
core.protobuf.RpcFrequency nco2 = 2;
}
您应该将其更改为:
message RpcNco {
RpcDeviceIdentifier OBSOLETE_deviceId = 1;
core.protobuf.RpcFrequency nco1 = 2;
core.protobuf.RpcFrequency nco2 = 3;
}
那么你的客户端和服务器将能够相互通信,无论它们是旧的还是新的 protobuf 定义。
我们正在对远程系统上的 运行 我们的硬件实施 client/server 应用程序。
为此,我们使用 GRPC、protobuf v3。
当我们修改 .proto
文件并在不更新服务器的情况下重新编译客户端时,我们收到一条带有模糊消息的异常:
Exception was thrown by handler.
使用 GRPC,检测 client/server 版本不匹配的常用方法是什么?
编辑:修改示例
例如我们改变这个(消息参数的特定类型):
service RpcAcquisitionCard {
...
rpc SetNumericalControlOscillator(RpcNcoConfiguration)
...
}
message RpcNco {
RpcDeviceIdentifier deviceId = 1;
core.protobuf.RpcFrequency nco1 = 2;
core.protobuf.RpcFrequency nco2 = 3;
}
至此(消息参数的通用类型)
service RpcAcquisitionCard {
...
rpc SetNumericalControlOscillator(RpcCommandParameter)
...
}
message RpcCommandParameter {
RpcDeviceIdentifier deviceId = 1;
google.protobuf.Any parameter = 2;
}
message RpcNco {
core.protobuf.RpcFrequency nco1 = 1;
core.protobuf.RpcFrequency nco2 = 2;
}
其中 RpcCommandParameter.parameter
字段是 RpcNco
。
使用protobuf时推荐阅读Language Guide.
https://developers.google.com/protocol-buffers/docs/proto3#updating 与您的场景特别相关:
Fields can be removed, as long as the tag number is not used again in your updated message type. You may want to rename the field instead, perhaps adding the prefix "OBSOLETE_", or make the tag reserved, so that future users of your .proto can't accidentally reuse the number.
那是你做错的地方。而不是改变:
message RpcNco {
RpcDeviceIdentifier deviceId = 1;
core.protobuf.RpcFrequency nco1 = 2;
core.protobuf.RpcFrequency nco2 = 3;
}
至:
message RpcNco {
core.protobuf.RpcFrequency nco1 = 1;
core.protobuf.RpcFrequency nco2 = 2;
}
您应该将其更改为:
message RpcNco {
RpcDeviceIdentifier OBSOLETE_deviceId = 1;
core.protobuf.RpcFrequency nco1 = 2;
core.protobuf.RpcFrequency nco2 = 3;
}
那么你的客户端和服务器将能够相互通信,无论它们是旧的还是新的 protobuf 定义。