I have to make paginated API calls, using Webclient and combine all the result at last. For ex : Person latest 1000 transaction details. In one call, i am gonna get max 100 Objects in json response (List). I can only get maximum 1000 records for this Person.
In pseudo code - java, it could look something like this
int Total = 1000;
int maxEachCall = 100;
int noOfCalls = maxTotal/maxEachCall;
int startIndex = 0;
List<MyDto> mailList = new ArrayList();
for(int i =startIndex; i<noOfCalls ;i+100){
List<MyDto> list = webClient.get().uri(baseUri+"?startIndex"+startIndex)
.retrieve()
.bodyToMono(MyDto.class)
.retry(3)
.block();
mainList.addAll(list);
if(startIndex>900 || list.size()<100){
break;
}
}
How can i write the same thing in reactive way WITHOUT blocking in spring mvc ?
Something like this??? I dont know. Help me
int Total = 1000;
int maxEachCall = 100;
int noOfCalls = maxTotal/maxEachCall;
int startIndex = 0;
Flux.range(1,noOfCalls)
.flatMap(
// tried to call api using startIndex but can't use startIndex here or manipulate it
)
.doOnError(e->LOGGER.info("Exception occured ",e))
.blockLast(); ???