0

Hello we have a Spring WebFlux based application that needs to make a GRPC call to another server that we are working with. I understand that we can use WebFlux's built in WebClient class for making http calls in a reactive way, but I am wondering how we can make GRPC calls in a similar fashion. Right now we are making outbound grpc calls by making a blocking grpc call on a different thread like this.

      Mono<Response> responseMono =  Mono.just(req)
            .publishOn(Schedulers.boundedElastic())
            .flatMap(request -> Mono.just(blockingStub.myMethod(req)))

Is there a way to make these outbound grpc calls in a similar way to how we can make call using the built in WebClient class such that it is reactive and we don't need to use the blocking stub nor make the call on a separate thread?

Aaron
  • 203
  • 1
  • 4
  • 15
  • 1
    As per the docs, that's how you're supposed to do it. – K.Nicholas Jun 08 '21 at 18:31
  • I don't think it is a good idea to call gRPC by WebClient, it's hardly to make a request without generated code. `Mono.just(blockingStub.myMethod(req))` should be enough, beacuse gRPC will call another thread to execute request. If you still want use same thread pool, you can use the `Schedulers.boundedElastic()`'s thread pool as gRPC stub thread pool when create channel. – HelloWood Jun 09 '21 at 01:45

0 Answers0