问题
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