使用Spring 5,结合Reactor,我们有以下需求。
有哪些方法可以将 Mono<List<String>> 转换为 Flux<String>?
Mono<TheResponseObject> getItemById(String id){
return webClient.uri('/foo').retrieve().bodyToMono(TheResponseObject)
}
Mono<List<String>> getItemIds(){
return webClient.uri('/ids').retrieve().bodyToMono(List)
}
Mono<RichResonseObject> getRichResponse(){
Mono<List> listOfIds = Mono.getItemIds()
listOfIds.each({ String id ->
? << getItemById(id) //<<< how do we convert a list of ids in a Mono to a Flux
})
Mono<Object> someOtherMono = getOtherMono()
return Mono.zip((? as Flux).collectAsList(), someOtherMono).map({
Tuple2<List, Object> pair ->
return new RichResonseObject(pair.getT1(), pair.getT2())
}).cast(RichResonseObject)
}
有哪些方法可以将 Mono<List<String>> 转换为 Flux<String>?
Flux.fromIterable()
而不是创建两个新数组。 - Leonard Brünings