Reputation: 54
I'm trying do some reverse engineering trying to understand what services are called among several .proto files. My question is if it's possible to implement a service on the server that handles all the call made and gives me the information of which function and service was called.
protocol.proto
syntax = "proto3";
package greating;
message PersonRequest {
string name = 1;
int32 age = 2;
}
message PersonResponse {
string message = 1;
}
service GreatingService {
rpc helloPerson (PersonRequest) returns (PersonResponse);
}
service WarningService {
rpc attentionPerson (PersonRequest) returns (PersonResponse);
}
server.js
const packageDefinition = protoLoader.loadSync("greating.proto");
const greatingProto = grpc.loadPackageDefinition(packageDefinition);
var server = new grpc.Server();
server.addService(greatingProto.greating.GreatingService.service, {
helloPerson: function(call, callback) {
let response = `Hello ${call.request.name}! You're ${call.request.age} years old`;
return callback(null, { message: response });
}
});
server.addService(greatingProto.greating.WarningService.service, {
helloPerson: function(call, callback) {
let response = `Attention ${call.request.name}! You're ${call.request.age} years left to live`;
return callback(null, { message: response });
}
});
What I want to do is to implement a 3rd function that handles both (all) calls, and displays which service was called. Something like this:
server.addService("*", {
function(call, callback) {
let response = `The service ${call.service}, function ${call.function} was called.`;
return callback(null, { message: response });
}
});
Is there a way to do this?
Thank you.
Upvotes: 1
Views: 498
Reputation: 20267
No, grpc does not support wildcard method handlers, or any other way of handling every incoming request with a single handler.
Upvotes: 1