work hard work smart

专注于Java后端开发。 不断总结,举一反三。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Feign整合Ribbon负载均衡

Posted on 2020-03-22 15:02  work hard work smart  阅读(814)  评论(0编辑  收藏  举报

backend_show_consumer工程

1、在 中配置FeignClient,name为back_show_provider的hello-service-provider

 

 

2、负载均衡器配置如下

@Configuration
public class RestConfig {

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
        return  new RestTemplate();
    }

    /**
     * 负载均衡规则
     * @return
     */
    @Bean
    public IRule iRule(){
        return new RoundRobinRule();
        //return new MyRule();
    }

    @Bean
    public IPing iPing(){
        //return  new PingUrl(false,"/abc");
        return  new NIWSDiscoveryPing();
    }
}

  

3、测试

来自7101端口服务返回的数据

 

俩字7102端口返回的数据