功能区负载平衡算法

Ribbon load balance algorithms

我在我的微服务项目中使用 Spring Cloud with NetflixOSS。另外,我使用带有 Feign Client 的 Ribbon 作为我的客户端负载均衡器。我想知道,是否有可能为 Ribbon 实现或选择不同类型的负载平衡算法?因为据我了解,默认是循环。

提前致谢!

是的,这是可能的。有关如何自定义的完整详细信息,请参阅 the docs。对于 @FeignClient("foo") 和随机负载平衡规则,您可以这样做:

@Configuration
@RibbonClient(name = "foo", configuration = FooConfiguration.class)
public class TestConfiguration {
}

@Configuration
public class FooConfiguration {
    @Bean
    public IRule ribbonRule(IClientConfig config) {
        IRule rule = new RandomRule();
        rule.initWithNiwsConfig(config);
        return rule;
    }
}

有关更多实施,请参阅 ribbon wiki for some more details and here