Flux (WebClient) Parallel Calls and then Post Processing on Collected List

I have a use case where I need to Run WebClient on Parallel Calls for 10 Upstream systems and timeout is 450ms, few of the Upstream System gives result in 80-150ms as p99 latency and few takes around ~300ms. Here I need to collect data from each and then do the ranking. I need a suggestion here If I use Collect() and then go for Ranking will that be blocking the thread by any chance as I need to get the data from all first and then go for Ranking. Can someone explain the Thread flow here? Thanks in advance!

Example 1:

Flux.just("red", "white", "blue")


17:02:18.479 [main] INFO reactor.Flux.Array.1 - | onSubscribe([Synchronous Fuseable] FluxArray.ArraySubscription)
17:02:18.483 [main] INFO reactor.Flux.Array.1 - | request(unbounded)
17:02:18.483 [main] INFO reactor.Flux.Array.1 - | onNext(red)
17:02:18.484 [main] INFO reactor.Flux.Array.1 - | onNext(white)
17:02:18.484 [main] INFO reactor.Flux.Array.1 - | onNext(blue)
17:02:18.485 [main] INFO reactor.Flux.Array.1 - | onComplete()

Example 2:

Flux.just("red", "white", "blue")


17:03:10.556 [main] DEBUG reactor.util.Loggers$LoggerFactory - Using Slf4j logging framework
17:03:10.622 [main] INFO reactor.Flux.Array.1 - | onSubscribe([Synchronous Fuseable] FluxArray.ArraySubscription)
17:03:10.625 [main] INFO reactor.Flux.Array.1 - | request(unbounded)
17:03:10.626 [main] INFO reactor.Flux.Array.1 - | onNext(red)
17:03:10.626 [main] INFO reactor.Flux.Array.1 - | onNext(white)
17:03:10.626 [main] INFO reactor.Flux.Array.1 - | onNext(blue)
17:03:10.627 [main] INFO reactor.Flux.Array.1 - | onComplete()

In Example #2 I have added .collectList()

Read more here: https://stackoverflow.com/questions/64409611/flux-webclient-parallel-calls-and-then-post-processing-on-collected-list

Content Attribution

This content was originally published by Sushobhit Rajan at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: