Article Directory
How to use ribbon
1 启动类中RestTemplate对象生成的@Bean注解下加入@LoadBalanced注解
2 方法中restTemplate.getForObject("远程调用服务名称/方法", 返回的实体对象)
3 配置文件中修改负载均衡策略,其他修改方式参见`https://www.jianshu.com/p/508f62fa0de5`
Configuration file modification method of load balancing strategy
service-product:
ribbon:
NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule
Description: user-provider is the name of the service to be invoked, and the value is the policy object.
7 load balancing strategies for ribbon
Strategic Object | Brief introduction |
---|---|
com.netflix.loadbalancer.RandomRule | Random selection of services |
com.netflix.loadbalancer.RoundRobinRule | Linear polling, the default method |
com.netflix.loadbalancer.RetryRule | A retry mechanism is added on the basis of polling, that is, within the specified retry time, the linear polling strategy is used repeatedly to select available instances |
com.netflix.loadbalancer.WeightedResponseTimeRule | Extension of linear polling, the faster the response speed, the greater the selection weight and the easier it is to be selected |
com.netflix.loadbalancer.BestAvailableRule | Choose an instance with less concurrency |
com.netflix.loadbalancer.AvailabilityFilteringRule | Filter out the failed instances first, and then select the instances with less concurrency |
e | Filter out the failed instances first, and then select the instances with less concurrency |
com.netflix.loadbalancer.ZoneAwareLoadBalancer | Double filtering is used to filter instances and fault instances that are not in the same area at the same time, and select instances with less concurrency |