简介java
在上一节中,咱们讨论了feign+hystrix在项目开发中,除了考虑正常的调用以外,负载均衡和故障转移也是关注的重点,这也是feign + ribbon+hystrix的优点所在,本节咱们就讨论一下在feign中使用ribbon,有两种方式spring
1、经过在配置文件application.yml配置,开启ribbon,并指定调用生产者相对上一节能够不作任何更改,能够看项目(microservice-consumer-movie-feign-with-hystrix-hystrix-factory)app
项目结构以下:负载均衡
application.yml配置文件:dom
spring: application: name: microservice-consumer-movie-feign-with-hystrix-hystrix-factory server: port: 7901 eureka: client: healthcheck: enabled: true serviceUrl: defaultZone: http://jacky:admin@peer1:8761/eureka/,http://jacky:admin@peer2:8762/eureka/,http://jacky:admin@peer3:8763/eureka/ instance: prefer-ip-address: true microservice-provider-user: ribbon: NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 5000
2、经过经过写配置类,在启动类中指定ribbon配置类便可,能够看项目(microservice-consumer-movie-ribbon)分布式
代码结构图:ide
Spring Cloud大型企业分布式微服务云构建的B2B2C电子商务平台源码请加企鹅求求:一零三八七七四六二六微服务