I have a custom implementation of request marshaller (overriding
io.grpc.MethodDescriptor.Marshaller)
which I want to use, but I would need context information related to the
microservice call (specifically microservice method name being invoked). I
tried populating it in ServerInterceptor's interceptCall. My interceptor
code looks like this:
@Override
public <ReqT, RespT> Listener<ReqT> interceptCall(ServerCall<ReqT, RespT>
serverCall, Metadata metadata, ServerCallHandler<ReqT, RespT>
serverCallHandler) {
Context context = Context.current().withValue(MS_METHOD_NAME,
call.getMethodDescriptor().getFullMethodName());
return Contexts.interceptCall(context, serverCall, metadata, serverCallHandler);
}
But the context populated does not persist when unmarshalling of the
request stream takes place.
This is because
io.grpc.internal.ServerImpl.ServerTransportListenerImpl#streamCreatedInternal
creates new
io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener and
populates context using
io.grpc.internal.ServerImpl.ServerTransportListenerImpl#createContext which
just adds deadline and serverImpl instance fields over rootContext. So, the
information I populated was not available during unmarshalling. Also,
populating it in onMessage would not be useful too, since
io.grpc.internal.ServerCallImpl.ServerStreamListenerImpl#messagesAvailableInternal
uses
listener.onMessage(call.method.parseRequest(message));
so parseRequest executes before onMessage is triggered.
Is there some way to pass context information to marshaller, or maybe use
method name there. I am constructing methodDescriptor using
io.grpc.MethodDescriptor.Builder
--
You received this message because you are subscribed to the Google Groups
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/grpc-io/3d7873fd-025b-4b09-8538-e55563ef053an%40googlegroups.com.