My rest client implementation is using Webflux from Project Reactor and is similar to the following:
Flux<Response1> request1(String uri) {
return webClient
.get()
.uri(uri)
.retrieve()
.bodyToMono(Responses1.class)
.map(r -> response1ToList(r))
.flatMapMany(Flux::fromIterable);
}
Flux<Response2> request2(Response1 response1) {
uri = f(response1);
return webClient
.get()
.uri(uri)
.retrieve
.bodyToMono(Responses2.class)
.map(r -> response1ToList(r))
.flatMapMany(Flux::fromIterable);
}
Flux<Response2> res2 = res1.flatMap(request2).subscribe();
The initial request (request1) returns a list of elements used to send a series of requests (request2).
My problem is that the request2s are all sent in parallel which is too heavy for the server.
Is there a way to limit the number of request2s executed at the same time?