Ribbon load balance algorithms

烈酒焚心 提交于 2019-12-10 15:53:49

问题


I am using Spring Cloud with NetflixOSS in my microservice project. Also, I am using Ribbon with Feign Client as my client side load balancer. I was wondering, is there any possibility to implement or choose different types of load balancing algorithms for Ribbon? Because as I understood, the default is round robin.

Thanks in advance!


回答1:


Yes, it is possible. See the docs for full details how to customize. For a @FeignClient("foo") and a random load-balancing rule you could do:

@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;
    }
}

See the ribbon wiki for some more details and here for more implementations.



来源:https://stackoverflow.com/questions/40992876/ribbon-load-balance-algorithms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!