Java gRPC从ServerInterceptor获取服务名称

db8*_*b80 5 java proto grpc

我正在使用 gRPC,我需要从 ServerInterceptor 获取请求的服务名称,但似乎这是不可能的。

基本上,从ServerInterceptor的实现中,我需要知道将调用的 ServiceGrpc 的名称(作为字符串)。

public class PermissionInterceptor implements ServerInterceptor {

        @Override
        public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
                ServerCall<ReqT, RespT> serverCall, Metadata metadata, ServerCallHandler<ReqT, RespT> handler
        ) {
            // here I need the name of RPC service that has been requested

            return handler.startCall(serverCall, metadata);
        }
}
Run Code Online (Sandbox Code Playgroud)

请注意,我尝试过使用serverCall.getMethodDescriptor()但它返回原始服务的名称而不是(java)服务的真实名称。

它返回:

co.test.domain.transaction.TransactionService
Run Code Online (Sandbox Code Playgroud)

但我需要这个:

co.test.domain.transaction.TransactionNeoBasicImpl
Run Code Online (Sandbox Code Playgroud)

谢谢

Eri*_*son 1

这是不可能的。

如果您的拦截器是应用程序之前的最后一个拦截器,您也许可以检查handler的类并查看其父类的名称。但这非常有限,并且不一定得到支持。