我希望能够转发一个
RPC
根据消息的内容调用不同的实现。
我做过调查
GRPC interceptors
但网站对此并没有很好的解释。我似乎找不到关于这个问题的好文件
我的
proto
文件看起来像:
message RPCParameters {
enum DataSource {
DS1 = 0;
DS2 = 1;
...
DS100 = 99;
}
int32 param1 = 1;
...
DataSource datasource = 10;
}
...
...
message Result {
...
}
service MyService {
rpc func1(RPCParameters) returns (Something) {}
....
rpc func100(RPCParameters) returns (Something) {}
}
现在在我的代码中,我想基于datasource值有条件地实现函数
即。:
MyServiceImplementation
implementation func1(params: Params) {
switch on params.datasource {
case DS1 => implementation 1
case DS2 => implementation 2
..
case DS100 => implementation 100
}
}
implementation func2(params: Params) {
switch on params.datasource {
case DS1 => implementation 1
case DS2 => implementation 2
..
case DS100 => implementation 100
}
}
...
implementation func100(params: Params) {
switch on params.datasource {
case DS1 => implementation 1
case DS2 => implementation 2
..
case DS100 => implementation 100
}
}
所以基本上这是非常麻烦和容易出错的-我需要添加一堆锅炉板到每个函数
我想知道我是否可以创建不同的实现程序,然后通过中间件将RPC调用转发到正确的版本,该版本应该执行逻辑。