重读spring coud --------Ribbon

  1. 7种负载均衡策略:
    1).随机策略
    2).轮询策略
    3).重试策略 在配置时间段内如果访问不成功,会不断尝试访问一个可用服务
    4).最低并发策略
    5).可用过滤策略 (过滤掉高并发和连接失败的服务)
    6)响应时间加权策略
    7)区域权衡策略

  2. 配置全局策略

@Configuration
public class RibbonConfig {

    @Bean
    public IRule ribbonRule(){
        return new RandomRule();
    }
}

  1. 配置单独策略
    注:avoidscan为自定义注解,用来关闭自动扫描
@Configuration
@AvoidScan
public class RibbonConfig {

//    @Bean
//    public IRule ribbonRule(){
//        return new RandomRule();
//    }

    @Autowired
    IClientConfig config;

    @Bean
    public IRule ribbonRule(IClientConfig config){
        return new RandomRule();
    }
}
//启动类添加的注解
@RibbonClient(name="wwmxd-auth",configuration = RibbonConfig.class)
@ComponentScan(excludeFilters = {@ComponentScan.Filter(type= FilterType.ANNOTATION,value = {AvoidScan.class})})
  1. Ribbon默认采用实际调用时再加载上下文,经常导致首次调用失败,未防止这种情况,可以采用饥饿加载
ribbon:
  eager-load:
    enabled: true
    clients: wwmxd-auth

5.实现原理
将由@LoadBalance注解的restTemplate类,通过@AutoWire注入到list里
在LoadBalancerAutoConfiguration类中,绑定ribbon的拦截器,在拦截器里进行负载均衡(在LoadBalancerClient接口的实现类中进行处理)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值