Load Balance Extension

Load Balance Extension

Extension Description

Select one from multiple service providers for invocation.

Extension Interface

org.apache.dubbo.rpc.cluster.LoadBalance

Extension Configuration

  1. <dubbo:protocol loadbalance="xxx" />
  2. <!-- Default value settings, when <dubbo:protocol> does not configure loadbalance, this configuration is used -->
  3. <dubbo:provider loadbalance="xxx" />

Known Extensions

  • org.apache.dubbo.rpc.cluster.loadbalance.RandomLoadBalance
  • org.apache.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance
  • org.apache.dubbo.rpc.cluster.loadbalance.LeastActiveLoadBalance
  • org.apache.dubbo.rpc.cluster.loadbalance.ConsistentHashLoadBalance
  • org.apache.dubbo.rpc.cluster.loadbalance.ShortestResponseLoadBalance

Extension Example

Maven project structure:

  1. src
  2. |-main
  3. |-java
  4. |-com
  5. |-xxx
  6. |-XxxLoadBalance.java (implements LoadBalance interface)
  7. |-resources
  8. |-META-INF
  9. |-dubbo
  10. |-org.apache.dubbo.rpc.cluster.LoadBalance (plain text file, content: xxx=com.xxx.XxxLoadBalance)

XxxLoadBalance.java:

  1. package com.xxx;
  2. import org.apache.dubbo.rpc.cluster.LoadBalance;
  3. import org.apache.dubbo.rpc.Invoker;
  4. import org.apache.dubbo.rpc.Invocation;
  5. import org.apache.dubbo.rpc.RpcException;
  6. public class XxxLoadBalance implements LoadBalance {
  7. public <T> Invoker<T> select(List<Invoker<T>> invokers, Invocation invocation) throws RpcException {
  8. // ...
  9. }
  10. }

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

  1. xxx=com.xxx.XxxLoadBalance

Feedback

Was this page helpful?

Yes No

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