We have a Spring Webflux based application, which returns a flux response. The application itself makes blocking calls to downstream services, and essentially acts as an aggregator. Each downstream request is a blocking HTTP POST request, and can take a variable amount of time (in the order of several seconds).
The current pattern we follow is to have the following:
Mono.fromCallable(() -> {
//client code for the blocking call
}).subscribeOn(Schedulers.boundedElastic()).flux()
If we have a large number of incoming connections this essentially means that we keep creating a lot of threads for these connections, and each thread is blocked on waiting for the response.
Would it better to use a AsyncHTTPClient instead, which would use NIO to issue non-blocking requests from within regular operations. Can anyone give an example for how this would work, and what are possible advantages/disadvantages to this approach?