I want to be able to forward a RPC
call to a different implementation based on the content of a message.
I've research GRPC interceptors
but the website doesn't have a good explanation on this. I can't seem to find good documentation on the subject
My proto
file looks like:
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) {}
}
Now in my code I want to conditionally implement the functions based on the datasource value
Currently I am doing a conditional check in each function
i.e.:
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
}
}
So basically this is very cumbersome and error prone - i need to add a bunch of boiler plate to each function
I'm wondering if i can instead create different implementors and then through middle ware forward the RPC call to the correct version which should perform the logic.