java - 如何将 Flux<List<T>> 扁平化为 Flux<T>?

标签 java spring spring-webflux project-reactor

你好,我的代码是这样的:

fun mapBatch(batch: List<String>): Mono<List<MyClass>> ...

fun myFun(stream: Flux<String>): Flux<MyClass> {
    return stream
            .bufferTimeout(50, Duration.ofSeconds(60L))
            .flatMap{ batch -> mapBatch(batch) }
            /// now here I would like to get Flux<MyClass> but have Flux<List<MyClass>> 
}

如何获取 Flux<T>来自 Flux<List<T>>

最佳答案

您应该使用 .concatMapIterable.flatMapIterable

Flux#flatMapIterable 是一个特殊的运算符,用于将表示为 Iterable 的项目“扁平化”为 T 的 react 流。

关于java - 如何将 Flux<List<T>> 扁平化为 Flux<T>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67972425/

相关文章:

java - Java中的内存泄漏

java - EL 内表格 :input causes unclosed tag error

java - 如何在Spring Boot应用程序的main方法中正确初始化Bean?

spring-boot - Spring Boot Webflux Security - 编写测试时读取服务类中的 Principal

spring-webflux - Spring WebFlux - 通过 webClient 转发 FilePart

java - 这是 java 中用于数据库到数据库之间数据迁移的最佳 API

java.lang.ClassCastException : net. sf.ehcache.hibernate.SingletonEhCacheRegionFactory 无法转换为 org.hibernate.cache.RegionFactory

java - 通过java中的参数集找到最合适的对象

java - Maven Spring Boot 应用程序启动失败 - JmxAutoConfiguration.mbeanExporter

java - Spring webflux Controller : consuming POJO vs Mono?