Dubboのクラスタフォールトトレランスモード:Failfast Cluster
9340 ワード
DubboのFailfast Clusterについて簡単に説明します.すべて
1概要
インスタンスの呼び出しに失敗した後、エラーが発生した場合、例外が直接放出されます.
2使用方法
または
3実装ロジック負荷等化アルゴリズムに従って呼び出されたインスタンス が選択する.選択したインスタンス を実行する.実行が成功すると戻る.異常がある場合はそのまま異常を投げ出す、再試行等の操作を行わない .
4実装コード
dubbo-cluster
サブディレクトリにあります.1概要
インスタンスの呼び出しに失敗した後、エラーが発生した場合、例外が直接放出されます.
2使用方法
<dubbo:service cluster="failfast" />
または
<dubbo:reference cluster="failfast" />
3実装ロジック
4実装コード
public class FailfastClusterInvoker<T> extends AbstractClusterInvoker<T> {
public FailfastClusterInvoker(Directory<T> directory) {
super(directory);
}
@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);
}
}
}