【问题标题】:How to create Flux from Mono如何从 Mono 创建 Flux
【发布时间】:2018-03-09 09:36:12
【问题描述】:

我有一个 Mono A。对象 A 包含两个列表。我想直接创建两个 Flux。没有block()这可能吗?

Mono<A> a = ... ;

Flux<AList1> a1 =  Flux.fromIterable(a.block().getList1());

【问题讨论】:

    标签: java java-stream spring-webflux


    【解决方案1】:

    使用 Mono.flatMapMany() 方法:

        Flux flux1 = mono.map(A::getList1).flatMapMany(Flux::fromIterable);
        Flux flux2 = mono.map(A::getList2).flatMapMany(Flux::fromIterable);
    

    【讨论】:

      猜你喜欢
      • 2020-11-19
      • 2020-01-02
      • 2021-08-02
      • 2019-01-21
      • 2018-10-15
      • 2019-06-06
      • 2020-08-28
      • 1970-01-01
      • 2020-02-28
      相关资源
      最近更新 更多