Class GrpcServerContextPropagationInterceptor
- All Implemented Interfaces:
io.grpc.ServerInterceptor, io.micronaut.core.order.Ordered
PropagatedContext that outer server interceptors make current when they start a call
into every later event of that call, so that the service method sees it.
gRPC delivers a call's events (onMessage, onHalfClose, onCancel, onComplete and
onReady) as separate tasks on the server executor, possibly on different threads. A unary service method
runs in onHalfClose, so a context an interceptor propagates around next.startCall(..), for example
with context.plus(element).propagate(() -> next.startCall(call, headers)), would otherwise be lost before the
method runs.
The interceptor runs last, closest to the service, so it captures the context of interceptors registered as beans.
Interceptors applied to a single service with ServerInterceptors.intercept(..) run inside it and are not
captured. The snapshot is only a fallback: an event that already runs inside a propagated context, for example one an
outer interceptor set around that event, keeps it. The interceptor does nothing when no context is propagated.
Enabled by default; disable with grpc.server.context-propagation.enabled=false.
- Since:
- 5.3.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe property that enables server context propagation.Fields inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintgetOrder()Runs last, so that the context set by every other interceptor is captured.<ReqT,RespT>
io.grpc.ServerCall.Listener<ReqT> interceptCall(io.grpc.ServerCall<ReqT, RespT> call, io.grpc.Metadata headers, io.grpc.ServerCallHandler<ReqT, RespT> next)
-
Field Details
-
ENABLED
-
-
Constructor Details
-
GrpcServerContextPropagationInterceptor
public GrpcServerContextPropagationInterceptor()
-
-
Method Details
-
interceptCall
public <ReqT,RespT> io.grpc.ServerCall.Listener<ReqT> interceptCall(io.grpc.ServerCall<ReqT, RespT> call, io.grpc.Metadata headers, io.grpc.ServerCallHandler<ReqT, RespT> next) - Specified by:
interceptCallin interfaceio.grpc.ServerInterceptor
-
getOrder
public int getOrder()Runs last, so that the context set by every other interceptor is captured.- Specified by:
getOrderin interfaceio.micronaut.core.order.Ordered- Returns:
- The order
-