reactor.util.retry.retry中有什么函数可以在重试成功时使用吗



对于服务器发送的事件实现,重试成功后,我需要立即执行一些操作,在reactor.util.Retry.Retry中找不到任何方法。是否有其他替代方法可以执行doOnRetrySuccess(func(

我不知道有内置运算符可以做到这一点,但您可以使用AtomicBoolean来检测重试后是否立即出现onNext/onComplete信号:

final AtomicBoolean retrying = new AtomicBoolean();
monoOrFlux
.retryWhen(Retry
// Configure whatever retry behavior you want here.
// For simplicity, this example uses .indefinitely()
.indefinitely()
// Set the retrying flag to indicate that a retry is being attempted.
.doBeforeRetry(signal -> retrying.set(true)))
// Check and reset the retrying flag in doOnEach.
// This example uses doOnEach, which works for both Mono and Flux.
// If the stream is a Mono, then you could simplify this to use doOnSuccess instead.
.doOnEach(signal -> {
if ((signal.isOnNext() || signal.isOnComplete())
&& retrying.compareAndSet(true, false)) {
// This is the first onNext signal emitted after a retry,
// or the onComplete signal (if no element was emitted) after a retry.
}
});

最新更新