【问题标题】:Consume Mono value and use it to call another Mono使用 Mono 值并使用它来调用另一个 Mono
【发布时间】:2019-05-25 16:46:08
【问题描述】:

我的代码是这样构造的 -

Mono<Address> m1 = method1() // this call returns address
Mono<Boolean> m2 = method2() // this call uses ReactiveMongoTemplate and updates document in Mongo

我正在努力实现这一目标:

当 method1() 返回地址时,我需要使用它并调用 method2() 来更新 MongoDB 文档中的地址。也没有抛出异常。但是我在 method2() 中没有看到任何日志

代码:

Mono<Object> m1 = method1().map(address -> method2(address));

虽然调用了 method2(),但 MongoDB 中的文档更新并未发生。

【问题讨论】:

    标签: reactive-programming spring-webflux project-reactor


    【解决方案1】:

    您的代码 sn-p 返回 Mono&lt;Mono&lt;Boolean&gt;&gt;,因此没有订阅内部 Mono

    你可能应该像这样use the Mono.flatMap operator

    Mono<Boolean> m1 = method1().flatMap(address -> method2(address));
    

    这个操作符将使操作链变平。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-16
      • 1970-01-01
      • 1970-01-01
      • 2020-01-22
      • 2019-09-19
      • 1970-01-01
      • 2011-06-03
      • 1970-01-01
      相关资源
      最近更新 更多