GrpcClientCallScope
Available in a dev version: 0․11․0-grpc-186
How to configure
The scope of a single outgoing gRPC client call observed by a GrpcClientInterceptor.
An interceptor receives this scope instance for every call and can:
Inspect the RPC method being invoked.
Read or populate requestHeaders before the request is sent.
Read callOptions that affect transport-level behavior.
Register callbacks with onHeaders and onClose to observe response metadata and final status.
Cancel the call early via cancel.
Continue the call by calling proceed with a (possibly transformed) request Flow.
Transform the response by modifying the returned Flow.
val interceptor = object : GrpcClientInterceptor {
override fun <Request, Response> GrpcClientCallScope<Request, Response>.intercept(
request: Flow<Request>
): Flow<Response> {
// Example: add a header before proceeding
requestHeaders[MyKeys.Authorization] = token
// Example: modify call options
callOptions.timeout = 5.seconds
// Example: observe response metadata
onHeaders { headers -> /* inspect headers */}
onClose { status, trailers -> /* log status/trailers */}
// IMPORTANT: proceed forwards the call to the next interceptor/transport.
// If you do not call proceed, no request will be sent and the call is short-circuited.
return proceed(request)
}
}Type Parameters
the request message type of the RPC.
the response message type of the RPC.
Properties
Transport/engine options used for this call (deadlines, compression, etc.). Modifying this object is only possible before the call is proceeded.
Descriptor of the RPC method (name, marshalling, type) being invoked.
Outgoing request headers for this call.
Functions
Register a callback invoked when the call completes, successfully or not. The final status and trailing responseTrailers are provided.
Register a callback invoked when the initial response headers are received. Typical gRPC semantics guarantee headers are delivered at most once per call and before the first message is received.