project reactor遇到的坑

笔者最近在使用onErrorStop操作符的时候,发现并没有生效,异常还是被throw出来,并且日志打印了onErrorDroped。仔细看了onErrorStop的java doc发现,每个操作符都有自己的error mode support,即不是每个操作符都能用onErrorStop。

举例doOnNext

/**
     * Add behavior (side-effect) triggered when the {@link Flux} emits an item.
     * 

* *

* The {@link Consumer} is executed first, then the onNext signal is propagated * downstream. * * @param onNext the callback to call on {@link Subscriber#onNext} * *

Error Mode Support: This operator supports {@link #onErrorContinue(BiConsumer) resuming on errors} * (including when fusion is enabled). Exceptions thrown by the consumer are passed to * the {@link #onErrorContinue(BiConsumer)} error consumer (the value consumer * is not invoked, as the source element will be part of the sequence). The onNext * signal is then propagated as normal. * * @return an observed {@link Flux} */ public final Flux doOnNext(Consumer onNext) { Objects.requireNonNull(onNext, "onNext"); return doOnSignal(this, null, onNext, null, null, null, null, null); }

中间有一句 *

Error Mode Support: This operator supports {@link #onErrorContinue(BiConsumer) resuming on errors}
意思就是doOnNext只能用onErrorResume

你可能感兴趣的:(project reactor遇到的坑)