叢集擴展
擴充說明
當有多個服務提供者時,將多個服務提供者組織成一個叢集,並模擬成一個提供者。
擴充埠
org.apache.dubbo.rpc.cluster.Cluster
擴充組態
<dubbo:protocol cluster="xxx" />
<!-- Default value configuration, if <dubbo:protocol> is not configured with cluster, use this configuration -->
<dubbo:provider cluster="xxx" />
已知擴充
org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterWrapper
org.apache.dubbo.rpc.cluster.support.FailoverCluster
org.apache.dubbo.rpc.cluster.support.FailfastCluster
org.apache.dubbo.rpc.cluster.support.FailsafeCluster
org.apache.dubbo.rpc.cluster.support.FailbackCluster
org.apache.dubbo.rpc.cluster.support.ForkingCluster
org.apache.dubbo.rpc.cluster.support.AvailableCluster
org.apache.dubbo.rpc.cluster.support.MergeableCluster
org.apache.dubbo.rpc.cluster.support.BroadcastCluster
org.apache.dubbo.rpc.cluster.support.registry.ZoneAwareCluster
擴充範例
Maven 專案結構
src
|-main
|-java
|-com
|-xxx
|-XxxCluster.java (implements the Cluster interface)
|-resources
|-META-INF
|-dubbo
|-org.apache.dubbo.rpc.cluster.Cluster (plain text file, content: xxx=com.xxx.XxxCluster)
XxxCluster.java
package com.xxx;
import org.apache.dubbo.rpc.cluster.Cluster;
import org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker;
import org.apache.dubbo.rpc.cluster.Directory;
import org.apache.dubbo.rpc.cluster.LoadBalance;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcException;
public class XxxCluster implements Cluster {
public <T> Invoker<T> merge(Directory<T> directory) throws RpcException {
return new AbstractClusterInvoker<T>(directory) {
public Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
//...
}
};
}
}
META-INF/dubbo/org.apache.dubbo.rpc.cluster.Cluster
xxx=com.xxx.XxxCluster
最後修改日期:2023 年 1 月 2 日:增強英文文件 (#1798) (95a9f4f6c1c)