Webflux:重复用完后的 OnErrorResume 未被触发

Webflux: OnErrorResume after repeats are exhausted is not being triggered

我正在尝试使用 onErrorResume 在重复耗尽后执行代码,但没有触发 onErrorResume。

这是代码示例

Mono.just(request)
                .filter(this::isConditionSatified)
                .map(aBoolean -> performSomeOperationIfConditionIsSatified(request))
                .repeatWhenEmpty(Repeat.onlyIf(i -> true)
                        .exponentialBackoff(Duration.ofSeconds(5)), Duration.ofSeconds(10))
                        .timeout(Duration.ofSeconds(30)))
                .delaySubscription(Duration.ofSeconds(10)))
                .onErrorResume(throwable -> {
                    log.warn("Max timeout reached", throwable);
                    return Mono.just(false);
                });

onErrorResume 永远不会被触发。我正在尝试将其用作后备。我的目标是如果达到重复耗尽,return false 值。

我的单元测试抱怨

expectation "expectNext(false)" failed (expected: onNext(false); actual: onComplete())

任何帮助或建议都会有所帮助。

由于 empty 来源本身有效,因此 repeatWhenEmpty 在用尽其尝试后不一定传播异常。来自 addons 的 Repeat util 没有,即使 "timeout" 触发(如 timeout 参数的 javadoc 中所暗示:"timeout after which no new repeats are initiated",好的,这可能更清楚)。

由于您使用的是 repeatWhenEMPTY,我猜对您来说空壳总是 "irrelevant",因此 defaultIfEmpty(false) 应该是可以接受的解决方案。