Reactive Quarkus gRPC Interceptor / How to interact with non-blocking call in ServerInterceptor #34322
-
Given a reactive non-blocking auth service like so: public interface AuthService {
Uni<Claims> verify(String token);
} How does one implement a gRPC interceptor that invokes a reactive / non-blocking methods e.g.: @GrpcService
@RegisterInterceptor(AuthInterceptor.class)
public class GrpcService implements Api {
public Uni<Response> request(Response response) {}
}
@ApplicationScoped
public class AuthInterceptor implements ServerInterceptor {
@Inject
AuthService authService;
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
ServerCall<ReqT, RespT> serverCall,
Metadata metadata,
ServerCallHandler<ReqT, RespT> serverCallHandler
) {
// Obviously we cannot block here or Vert.x will pitch a fit...
authService.verify(metadata.get(AUTHORIZATION_HEADER_KEY)).await().indefinitely();
return serverCallHandler.startCall(serverCall, metadata);
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
manofthepeace
Jul 12, 2023
Replies: 2 comments 2 replies
-
/cc @alesj (grpc), @cescoffier (grpc) |
Beta Was this translation helpful? Give feedback.
0 replies
-
This is related to a similar question about calling non-blocking @cescoffier , @manofthepeace Sorry to bother, could you please advise? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@paiyar I have answered the followup question and added a sample app in the other discussion you linked. Generally I would suggest not using an interceptor for that purpose, but the app I have linked shows does work. Basically the thing is that the subscription must not happen in the interceptor. hope that helps.