【发布时间】:2022-01-08 06:02:50
【问题描述】:
Flux 发出的项目(在本例中为“Red”、“White”、“Blue”)被传递给外部服务调用。我从returnValue 中的外部服务获取响应值。如何将发送到外部服务的元素与收到的响应进行映射?
@Log4j2
@SpringBootApplication
class FluxFromIterableAccessFlatMapValue implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
Flux.just("Red", "White", "Blue").
flatMap(colors -> Mono.fromCallable(() -> {
// > Call to external service made here.
return "Return value from external Service call.";
})).subscribeOn(Schedulers.single())
.subscribe(returnValue ->
log.info("Need to access which element produced this response?" +
"Is it response for Red, White or Blue? " + returnValue));
}
}
【问题讨论】:
标签: java spring spring-boot spring-webflux project-reactor