Ribbon负载均衡策略

Ribbon负载均衡策略_第1张图片

application.yml 针对某一个微服务设置负载均衡

book-service: #微服务id
  ribbon:
    NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule #随机策略

全局设置,全局设置优先级高于application.yml设置

@SpringBootApplication
@EnableEurekaClient
public class MemberServiceApplication {
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }
    @Bean //全局负载均衡策略
    public IRule ribbonRule(){
        return new RoundRobinRule();
    }
    public static void main(String[] args) {
        SpringApplication.run(MemberServiceApplication.class, args);
    }

}

你可能感兴趣的:(spring,cloud)