spring-webflux - 我什么时候使用 Mono.flatMapIterable 和 Mono.flapMapMany?

标签 spring-webflux project-reactor

react 堆新手,试图了解 Mono.flatMapManyMono.flatMapIterable经常处理包含集合的对象的 Mono。

有什么区别:

        Mono.just(List.of("one", "two", "three")).log().flatMapMany(Flux::fromIterable).subscribe(System.out::println);
        Mono.just(List.of("one", "two", "three")).log().flatMapIterable(l -> l).subscribe(System.out::println);


我什么时候使用每种方法?

谢谢

最佳答案

Mono#flatMapMany是一个通用的一对多运算符。Mono#flatMapIterable是一个特殊的运算符,用于“展平”表示为 Iterable<T> 的项目进入 T 的 react 流.

使用 Mono#flatMapIterable在可能的情况下(映射器可以返回 Iterable),因为它已优化,请使用 Mono#flatMapMany当您的映射器返回 Publisher 时项。

关于spring-webflux - 我什么时候使用 Mono.flatMapIterable 和 Mono.flapMapMany?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55966358/

相关文章:

java - spring webflux中Controller层错误处理错误

spring - Project Reactor 中的预取是什么意思?

java - 如何在 Mono 中抛出另一个异常?

java - 如何自定义 SpringWebFlux WebClient JSON 反序列化?

java - 有没有办法在 webflux 代码中等待异步方法结果

java - Kotlin,响应式(Reactive)编程 : How to consume the value of one function output to another one

spring-webflux - 获取 webflux 事件循环调度程序

java - 获取 react 流的排列

java - Schedulers.newElastic 和 Schedulers.elastic 方法有什么区别?

java - 在 Spring Webflux 中添加的多个 cookie 未合并到单个 HTTP header 中