假设我嵌套了下面的Flux和Mono。我有两个不同的Apache Cassandra表的信息。我想合并细节并发送回作为Flux。
请参考下面更新的伪代码。
@Autowired FollowersRepository followersRepository;
@Autowired TopicRepository topicRepository;
@GetMapping("/info")
public Flux<FullDetails> getData(){
return Flux.create(emitter ->{
followersRepository.findAll()
.doOnNext(data -> {
List<String> all = data.getTopiclist(); //will get list of topic id
List<Alltopics> processedList = new ArrayList<Alltopics>();
all.forEach(action -> {
topicRepository.findById(action) //will get full detail about topic
.doOnSuccess(topic ->{
processedList.add(topic);
if (processedList.size() >= all.size()) {
FullDetails fulldetails = new FullDetails(action,processedList);
emitter.next(fulldetails);
//emitter.complete();
}
})
.subscribe();
});
})
.doOnComplete(() ->{
System.out.println("All the data are processed !!!");
//emitter.complete(); // executing if all the data are pushed from database not waiting for doOnNext method to complete.
})
.subscribe();
});
}
有关更多详细信息,请参阅此处的代码CodeLink。
我已经尝试使用doOnComplete和doOnFinally作为外部通量,它不会等待所有内部非阻塞调用完成。
在处理完Flux中所有嵌套的单声道(非阻塞)请求后,我想调用onComplete。
https://stackoverflow.com/questions/51651010
复制相似问题