Search code examples
javarpcgrpcproto

Java, gRPC and Context propagation


Does anyone have a working example of io.grpc.Context propagation between client (stub) and server using gRPC in java?

My understanding is that it's not possible and I must use Metadata instead. Am I correct?

Online I have found only examples using Header rather than Context.

Thanks!


Solution

  • io.grpc.Context is for local propagation only, like between threads or even on the same thread. gRPC purposefully does not propagate items from it automatically. You can use a ClientInterceptor to copy a value from the Context to the Metadata.