Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagation mechanism which can carry scoped-values across API boundaries and between threads #393

Closed
svranesevic opened this issue Sep 12, 2018 · 6 comments

Comments

@svranesevic
Copy link

In Java gRPC we have Context which allows for propagation of scoped-values across API boundaries and threads, which is useful for propagating security principals and similar.

I did not manage to find equivalent, nor how to accomplish this functionality using akka-grpc, hence my questions are:

  • Is this functionality something that is planned for near future
  • For time being is there an undocumented work around for it
@htimur
Copy link

htimur commented Sep 14, 2018

We would like to migrate our current SclaPB based solution to akka-grpc, and this is the blocker we are facing. Can someone take a look, please?

@raboof
Copy link
Member

raboof commented Sep 14, 2018

For the client:

For the server:

  • You can 'wrap' the generated route like you can with any other Akka HTTP route. We should definitely provide some simple examples of how to do this, Add example of wrapping the generated route in a Directive #402.
  • We have been discussing different ways to provide a 'power API' for the server side, but didn't settle on anything yet. See Server-side power API #179 - your ideas are definitely welcome!
  • For the time being it's entirely possible to ignore the generated route and implement your own, using the generated serializers and other utilities in the grpc-runtime library. You can have a look at the generated route code for some inspiration.

Does this help?

@htimur
Copy link

htimur commented Sep 14, 2018

@raboof, thanks we will check this and get back to you.

@teimuraz
Copy link

teimuraz commented Sep 17, 2018

@raboof

You can 'wrap' the generated route like you can with any other Akka HTTP route. We should definitely provide some simple examples of how to do this, #402.

Do you mean akka-http routes? If yes, where those generated routes are located?

Or do you mean pattern matching over rpc name in generated service handler?

object UserServiceHandler {
	...

    def handle(request: HttpRequest, method: String): Future[HttpResponse] = method match {
      
      case "SignUp" =>
        val responseCodec = Codecs.negotiate(request)
        GrpcMarshalling.unmarshal(request)(SignUpRequestSerializer, mat)
          .flatMap(implementation.signUp(_))
          .map(e => GrpcMarshalling.marshal(e)(SignUpResponseSerializer, mat, responseCodec))
      
      case "SignIn" =>
        val responseCodec = Codecs.negotiate(request)
        GrpcMarshalling.unmarshal(request)(SignInRequestSerializer, mat)
          .flatMap(implementation.signIn(_))
          .map(e => GrpcMarshalling.marshal(e)(SignInResponseSerializer, mat, responseCodec))
      
      case m => Future.failed(new NotImplementedError(s"Not implemented: $m"))
    }
   ...
  }
}

If you mean the latter than yes, we could wrap this handler and check request headers, but the downside is the lack of compile time check.

Would be nice to have some example.

@raboof
Copy link
Member

raboof commented Sep 18, 2018

@teimuraz I indeed meant the latter. It's correct that this lacks a compile-time check that you implemented exactly the methods that were dictated by the .proto - that would be something we'd like to provide as part of #179.

@raboof
Copy link
Member

raboof commented Aug 16, 2021

We now have the power API and documentation for the Akka HTTP integration - I think I'd like to close this issue now, though feel free to open new ones for scenario's that aren't covered by the now-existing tools yet!

@raboof raboof closed this as completed Aug 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants