CompletableFuture - SupplyAsync for gRPC client Call

43 views
Skip to first unread message

Bhuvi Viji

unread,
Nov 17, 2020, 2:54:35 AM11/17/20
to grpc.io
Hi,

I have Service A which has to call Service B and C asynchronously. So i used Java 8 CompletableFuture supplyAsync method.

Problem: 
Service A gets JWT token from the caller , using Server interceptor it validates the token and if the token is valid it is set in the gRPC Context to propagate token to further client calls.

When i put the CompletableFuture , it creates a new thread for Service B and C calls so the gRPC context where the token set is lost. Service B and C calls are failing with missing token.


Background: Earlier Service A calls only B. So the ServerInterceptor which sets the token was available in clientInterceptor for calling B.

As a new enhancement added Service C call.


zda...@google.com

unread,
Nov 18, 2020, 2:36:15 PM11/18/20
to grpc.io
You might use 


and pass the second argument as context.fixedContextExecutor() or Context.currentContextExecutor().

Bhuvi Viji

unread,
Nov 19, 2020, 7:24:10 AM11/19/20
to grpc.io
Thank you. I have used Context.attach and detach . will try out this option as well.
Reply all
Reply to author
Forward
0 new messages