2

Java 11

Spring Boot 2.2.6

WebFlux Netty application using Flux.parallell streams on WebClient REST call:

private Mono<MySingleResponse> sendDocument(Document doc) {
    return documentWebClient
            .post()
            .uri("/upload")
            .contentType(MediaType.APPLICATION_JSON)
            .bodyValue(doc)
            .retrieve()
            .onStatus(HttpStatus::isError, clientResponse ->  Mono.error(new MyServerException()))
            .bodyToMono(MySingleResponse.class);
}

Set on a chain:

            .then(doStuff())
            .then(Flux.fromIterable(documents)
                            .parallel()
                            .runOn(Schedulers.elastic())
                            .flatMap(document -> sendDocument(document))
                            .sequential()
                            .reduce(new MyCompleteResponse(), myReduce()))
            .then(doOtherStuff());
}

Reduced whit:

BiFunction<MyCompleteResponse, MySingleResponse, MyCompleteResponse > myReduce () {
    return (o2, o1) -> {
        List< MySingleResponse> singleResponses = new ArrayList<>(o2.getSingleResponses());
        responses.add(o1);
        return new MyCompleteResponse(singleResponses);
    };
}

If the WebClient gets an error response, does the reduce collapse responding with a Mono.error() or does it collects all responses?

In other words: do I lose all information about the other REST requests?

Toerktumlare
  • 12,548
  • 3
  • 35
  • 54
mattobob
  • 833
  • 4
  • 15
  • 37
  • By the way, here is a partial answer: https://stackoverflow.com/questions/57534772/dealing-with-parallel-flux-in-reactor – mattobob Sep 03 '20 at 07:38

0 Answers0