【问题标题】:Project Reactor: Flux Timeout only if first item is not emittedProject Reactor:仅在未发出第一项时通量超时
【发布时间】:2020-07-08 13:48:37
【问题描述】:

我有一个通量,它应该几乎立即发射一个项目。在此之后,它可能不会在很长一段时间内发出项目。 如果最初没有收到任何物品,我希望它超时。但是如果我使用timeout(Duration) 方法,每次在给定的时间段内没有收到任何物品时它都会超时。

我现在的代码,由于上述原因不起作用:

messageFlux.timeout(Duration.ofSeconds(30)).doOnError(e -> {
    // handle error
}).subscribe(m -> messageService.consumeMessage(m));

有没有办法有效地做到这一点?

【问题讨论】:

    标签: java flux reactive


    【解决方案1】:

    这对我有用。 而不是:

    messageFlux.timeout(Duration.ofSeconds(30))
    

    我愿意:

    messageFlux.timeout(Mono.just(0L).delayElement(Duration.ofSeconds(30)))
    

    【讨论】:

      猜你喜欢
      • 2017-05-18
      • 1970-01-01
      • 1970-01-01
      • 2017-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-16
      • 1970-01-01
      相关资源
      最近更新 更多