当前位置 : 主页 > 编程语言 > java >

dubbo源码分析第十八篇一dubbo集群容错策略-FailfastCluster与FailsafeCluster

来源:互联网 收集:自由互联 发布时间:2023-02-04
文章目录 ​​FailfastClusterInvoker​​ ​​FailsafeClusterInvoker​​ FailfastClusterInvoker 失败后直接抛出异常 public Result doInvoke(Invocation invocation, ListInvokerT invokers, LoadBalance loadbalance) throws RpcEx

文章目录

  • ​​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 } }

上一篇:spring bean生命周期
下一篇:没有了
网友评论