在上一節中,咱們討論了feign+hystrix在項目開發中,除了考慮正常的調用以外,負載均衡和故障轉移也是關注的重點,這也是feign + ribbon+hystrix的優點所在,本節咱們就討論一下在feign中使用ribbon,有兩種方式spring
1、經過在配置文件application.yml配置,開啓ribbon,並指定調用生產者相對上一節能夠不作任何更改,能夠看項目(microservice-consumer-movie-feign-with-hystrix-hystrix-factory)docker
項目結構以下:架構
application.yml配置文件:app
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)瞭解springcloud架構能夠加求求:三五三六二四七二五九負載均衡