功能区负载均衡算法

bra*_*zic 4 spring load-balancing spring-boot spring-cloud spring-cloud-netflix

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

提前致谢!

spe*_*ibb 6

对的,这是可能的.有关如何自定义的完整详细信息,请参阅文档.对于a @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;
    }
}
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请参阅功能区wiki,此处了解更多实现.