负载均衡扩展

扩展说明

选择多个服务提供者之一进行调用

扩展点

org.apache.dubbo.rpc.cluster.LoadBalance

扩展配置

<dubbo:protocol loadbalance="xxx" />
<!-- Default value setting, when <dubbo:protocol> does not configure loadbalance, use this configuration -->
<dubbo:provider loadbalance="xxx" />

已知扩展

  • 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

扩展示例

Maven 项目结构

src
 |-main
    |-java
        |-com
            |-xxx
                |-XxxLoadBalance.java (implements the LoadBalance interface)
    |-resources
        |-META-INF
            |-dubbo
                |-org.apache.dubbo.rpc.cluster.LoadBalance (plain text file, content: xxx=com.xxx.XxxLoadBalance)

XxxLoadBalance.java

package com.xxx;
 
import org.apache.dubbo.rpc.cluster.LoadBalance;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.RpcException;
 
public class XxxLoadBalance implements LoadBalance {
    public <T> Invoker<T> select(List<Invoker<T>> invokers, Invocation invocation) throws RpcException {
        //...
    }
}

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

xxx=com.xxx.XxxLoadBalance

上次修改时间:2023 年 1 月 2 日:增强英文文档 (#1798) (95a9f4f6c1c)