I have 3 input IDs, which should be processed parallely. For that I have used ParallelFlux as below.
For every ID, there are 2 downstream API calls(mono1 and mono2 as below) that needs to be parallely invoked as well.
Will it be possible projectReactor?
I tried with following code. With parallel flux, each id will be processed with different threads. But the downstream calls will be sequential with same assigned thread.
Flux.fromIterable(idList)
.parallel()
.runOn(Schedulers.boundedElastic()
.flatMap(id -> Mono.fromCallable(()-> Pair.of(id, getInfoByID(id))))
.sequential()
.collect(Collector.toList()).block();
private Info getInfoByID(String id){
var mono1= api1.getDetails();
var mono2= api2.getDetails();
Mono.zip(mono1, mono2)
.map(tuple2 -> {
…………
}).block();
}
Thanks
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744111738a4558982.html
评论列表(0条)