注:dubbo的版本是2.6.2。
图1 Dubbo的FailfastClusterInvoker类继承图
Failfast可以理解为只发起一次调用,若失败则立即报错。
核心代码在FailfastClusterInvoker的doInvoke(Invocation,List<Invoker<T>>,LoadBalance)中,源码如下。
@Override
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);
}
}
这个比较简单,好理解。重点在失败之后不再进行重调等尝试。
(adsbygoogle = window.adsbygoogle || []).push({});