本文介绍了onErrorResume 和 doOnError 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在spring项目反应器中,onErrorResumedoOnError有什么区别?什么时候我应该每个人?

In spring project reactor, what are the differences between onErrorResume and doOnError ? and when I should each of them ?

推荐答案

onErrorResume:当上游发生异常时,给出一个回退流.

onErrorResume: Gives a fallback stream when some exception occurs happens in the upstream.

doOnError:副作用运算符.假设你想记录上游发生了什么错误.

doOnError: Side-effect operator. Suppose you want to log what error happens in the upstream.

示例:

Mono.just(request)
.flatMap(this::makeHTTPGet)
.doOnError(err -> {
        log.error("Some error occurred while making the POST call",err)
    })
.onErrorResume(err -> Mono.just(getFallbackResponse()));

你看,doOnError 是一个副作用操作符.这就像将温度计插入水管并读取温度.它会影响管道吗?号

You see, doOnError is a side-effect operator. It's like inserting a thermometer into a water pipeline and reading the temperature. Does it affect the pipeline at all? No.

假设现在管道破裂 - 城市仍然需要供水,对吗?所以我们有一个可以在这种情况下激活的回退管道.onErrorResume 就是这样做的.

Suppose now that the pipeline breaks - the city still has to get water right? So we have a fallback pipeline that can be activate in such cases. onErrorResume does exactly that.

注意:您也可以登录onErrorResume.没有什么能阻止你这样做.

Note: You could also log in onErrorResume. Nothing stops you from doing that.

这篇关于onErrorResume 和 doOnError 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 18:03