集群扩展

扩展说明

当有多个服务提供方时,将多个服务提供方组织成一个集群,并伪装成一个提供方。

扩展接口

org.apache.dubbo.rpc.cluster.Cluster

扩展配置

  1. <dubbo:protocol cluster="xxx" />
  2. <!-- 缺省值配置,如果<dubbo:protocol>没有配置cluster时,使用此配置 -->
  3. <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 项目结构:

  1. src
  2. |-main
  3. |-java
  4. |-com
  5. |-xxx
  6. |-XxxCluster.java (实现Cluster接口)
  7. |-resources
  8. |-META-INF
  9. |-dubbo
  10. |-org.apache.dubbo.rpc.cluster.Cluster (纯文本文件,内容为:xxx=com.xxx.XxxCluster)

XxxCluster.java:

  1. package com.xxx;
  2. import org.apache.dubbo.rpc.cluster.Cluster;
  3. import org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker;
  4. import org.apache.dubbo.rpc.cluster.Directory;
  5. import org.apache.dubbo.rpc.cluster.LoadBalance;
  6. import org.apache.dubbo.rpc.Invoker;
  7. import org.apache.dubbo.rpc.Invocation;
  8. import org.apache.dubbo.rpc.Result;
  9. import org.apache.dubbo.rpc.RpcException;
  10. public class XxxCluster implements Cluster {
  11. public <T> Invoker<T> merge(Directory<T> directory) throws RpcException {
  12. return new AbstractClusterInvoker<T>(directory) {
  13. public Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
  14. // ...
  15. }
  16. };
  17. }
  18. }

META-INF/dubbo/org.apache.dubbo.rpc.cluster.Cluster:

  1. xxx=com.xxx.XxxCluster

最后修改 September 21, 2021: Bug fix miss mialbox (#953) (57cf51b)