Search code examples
scalagrpcscalapb

Accessing GRPC context of request in scala


I can't find any example in scala/java where the server side is accessing the context of a grpc request (with scalapb / grpc.io). I can find many examples in golang. I found some of with akka grpc but I am using scalapb and grpc.io

If anyone knows of a repo in github that uses it or can layout the steps needs to access it, it would be very kind of you


Solution

  • In grpc-java and ScalaPB you get access to the request's metadata through client and server interceptors. See: https://grpc.github.io/grpc-java/javadoc/io/grpc/ServerInterceptor.html

    Example: https://github.com/saturnism/grpc-java-by-example/tree/master/metadata-context-example/src/main/java/com/example/grpc/server