dubbo源码第18篇:FailfastCluster与FailsafeCluster集群容错机制详解?

2026-05-24 00:431阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计247个文字,预计阅读时间需要1分钟。

dubbo源码第18篇:FailfastCluster与FailsafeCluster集群容错机制详解?

文章目录+ FailfastClusterInvoker+ FailsafeClusterInvoker+ FailfastClusterInvoker+ 失败后直接抛出异常+ public Result doInvoke(Invocation invocation, List invokers, LoadBalance loadbalance) throws RpcException

dubbo源码第18篇:FailfastCluster与FailsafeCluster集群容错机制详解?

文章目录

  • ​​FailfastClusterInvoker​​
  • ​​FailsafeClusterInvoker​​

FailfastClusterInvoker

  • 失败后直接抛出异常
public Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException { checkInvokers(invokers, invocation); Invoker<T> invoker = select(loadbalance, invocation, invokers, null); try { return invoker.invoke(invocation); } catch (Throwable e) { if (e instanceof RpcException && ((RpcException) e).isBiz()) { // biz exception. throw (RpcException) e; } throw new RpcException(e instanceof RpcException ? ((RpcException) e).getCode() : 0, "Failfast invoke providers " + invoker.getUrl() + " " + loadbalance.getClass().getSimpleName() + " select from all providers " + invokers + " for service " + getInterface().getName() + " method " + invocation.getMethodName() + " on consumer " + NetUtils.getLocalHost() + " use dubbo version " + Version.getVersion() + ", but no luck to perform the invocation. Last error is: " + e.getMessage(), e.getCause() != null ? e.getCause() : e); } }

FailsafeClusterInvoker

  • 失败后不抛出异常,构建null返回
@Override public Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException { try { checkInvokers(invokers, invocation); Invoker<T> invoker = select(loadbalance, invocation, invokers, null); return invoker.invoke(invocation); } catch (Throwable e) { logger.error("Failsafe ignore exception: " + e.getMessage(), e); return AsyncRpcResult.newDefaultAsyncResult(null, null, invocation); // ignore } }

本文共计247个文字,预计阅读时间需要1分钟。

dubbo源码第18篇:FailfastCluster与FailsafeCluster集群容错机制详解?

文章目录+ FailfastClusterInvoker+ FailsafeClusterInvoker+ FailfastClusterInvoker+ 失败后直接抛出异常+ public Result doInvoke(Invocation invocation, List invokers, LoadBalance loadbalance) throws RpcException

dubbo源码第18篇:FailfastCluster与FailsafeCluster集群容错机制详解?

文章目录

  • ​​FailfastClusterInvoker​​
  • ​​FailsafeClusterInvoker​​

FailfastClusterInvoker

  • 失败后直接抛出异常
public Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException { checkInvokers(invokers, invocation); Invoker<T> invoker = select(loadbalance, invocation, invokers, null); try { return invoker.invoke(invocation); } catch (Throwable e) { if (e instanceof RpcException && ((RpcException) e).isBiz()) { // biz exception. throw (RpcException) e; } throw new RpcException(e instanceof RpcException ? ((RpcException) e).getCode() : 0, "Failfast invoke providers " + invoker.getUrl() + " " + loadbalance.getClass().getSimpleName() + " select from all providers " + invokers + " for service " + getInterface().getName() + " method " + invocation.getMethodName() + " on consumer " + NetUtils.getLocalHost() + " use dubbo version " + Version.getVersion() + ", but no luck to perform the invocation. Last error is: " + e.getMessage(), e.getCause() != null ? e.getCause() : e); } }

FailsafeClusterInvoker

  • 失败后不抛出异常,构建null返回
@Override public Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException { try { checkInvokers(invokers, invocation); Invoker<T> invoker = select(loadbalance, invocation, invokers, null); return invoker.invoke(invocation); } catch (Throwable e) { logger.error("Failsafe ignore exception: " + e.getMessage(), e); return AsyncRpcResult.newDefaultAsyncResult(null, null, invocation); // ignore } }