Describe the bug
gRPC services should have the request scope enabled as, without it, they cannot use Hibernate Reactive.
Note that the EnableRequestScope annotation does not work in this case as it closes the request scope before the Uni / Multi gets the result.
Expected behavior
Service implementation should have the request scope enabled.
To Reproduce
Implement a Hello gRPC service and try accessing Hibernate Reactive session from within the method in a delayed (after the return of the method) manner.
I believe it would need a gRPC interceptor (or maybe a plain CDI interceptor).
/cc @Sanne, @aguibert, @gavinking, @gsmet, @michalszynkiewicz
@mkouba can we have a CDI interceptor enabling a request scope before the call of the method and disabling it once the returned Uni / Multi completes (or fails) ?
@cescoffier Well, you can have an interceptor that _starts_ a request context but does not _destroy_ it. Instead, it can just _deactivate_ the context, i.e. remove the threadlocal to avoid leaks. And then you can destroy the context once the Uni/Multi completes. This is what we do for reactive routes: https://github.com/quarkusio/quarkus/blob/master/extensions/vertx-web/runtime/src/main/java/io/quarkus/vertx/web/runtime/RouteHandler.java#L37-L58
CC @manovotn
Yes, it's easy to do for Reactive routes... a bit less easy with gRPC (they have their own interceptor stuff). That's why I was wondering about the CDI interceptor.
Well, gRPC interceptors, let's meet again (last time I won!)
Yes, it's easy to do for Reactive routes... a bit less easy with gRPC (they have their own interceptor stuff). That's why I was wondering about the CDI interceptor.
I'm not quite sure I understand ;-). So a CDI interceptor is always bound to a method invocation - once an invocation completes the interceptor is out of game.
But if my interceptor captures the produce Uni / Multi and attached the right code on termination, that would work right?
But if my interceptor captures the produce Uni / Multi and attached the right code on termination, that would work right?
Yes, that's basically what the RouteHandler does (it's kind of "manual" Handler.handle() interception).