美文网首页
project reactor遇到的坑

project reactor遇到的坑

作者: katkrazy | 来源:发表于2021-03-04 12:57 被阅读0次

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

举例doOnNext

/**
     * Add behavior (side-effect) triggered when the {@link Flux} emits an item.
     * <p>
     * <img class="marble" src="doc-files/marbles/doOnNextForFlux.svg" alt="">
     * <p>
     * The {@link Consumer} is executed first, then the onNext signal is propagated
     * downstream.
     *
     * @param onNext the callback to call on {@link Subscriber#onNext}
     *
     * <p><strong>Error Mode Support:</strong> 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<T> doOnNext(Consumer<? super T> onNext) {
        Objects.requireNonNull(onNext, "onNext");
        return doOnSignal(this, null, onNext, null, null, null, null, null);
    }

中间有一句 * <p><strong>Error Mode Support:</strong> This operator supports {@link #onErrorContinue(BiConsumer) resuming on errors}
意思就是doOnNext只能用onErrorResume

相关文章

网友评论

      本文标题:project reactor遇到的坑

      本文链接:https://www.haomeiwen.com/subject/xbfkqltx.html