4

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!

db80
  • 4,157
  • 1
  • 38
  • 38

1 Answers1

6

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.

Eric Anderson
  • 24,057
  • 5
  • 55
  • 76
  • Thanks for your answer. Out of curiosity, why is io.grpc.Context not propagated ? – db80 Mar 13 '18 at 14:12
  • 5
    What's propagated locally and remotely are fundamentally different. Context values aren't serialized, for instance. But even if they were, automatically sending arbitrary "ambient" values to remote hosts sounds scary and bug-prone. Context is similar to ThreadLocal; it'd be very strange to send ThreadLocals automatically to the remote. – Eric Anderson Mar 13 '18 at 15:47