Cluster extension

Cluster extension

Extension Description

When there are multiple service providers, organize them into a cluster and masquerade as a single provider.

Extension Interface

org.apache.dubbo.rpc.cluster.Cluster

Extension Configuration

  1. <dubbo:protocol cluster="xxx" />
  2. <!-- Default configuration; if <dubbo:protocol> does not configure cluster, this configuration will be used -->
  3. <dubbo:provider cluster="xxx" />

Known Extensions

  • 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

Extension Example

Maven project structure:

  1. src
  2. |-main
  3. |-java
  4. |-com
  5. |-xxx
  6. |-XxxCluster.java (implements Cluster interface)
  7. |-resources
  8. |-META-INF
  9. |-dubbo
  10. |-org.apache.dubbo.rpc.cluster.Cluster (plain text file with content: 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

Feedback

Was this page helpful?

Yes No

Last modified September 30, 2024: Update & Translate Overview Docs (#3040) (d37ebceaea7)