Eureka + Ribbon + Feign + Hystrix (使用熔断器Hystrix )

改造Eureka + Ribbon + Feign 负载均衡  点击进入查看

Step 3-1:修改application.properties,开启feign断路器功能

feign.hystrix.enabled=true

 注:不熟悉如何搭建Spring Boot 项目,请点击

 

Step 3-2:新建 SchedualServiceHiHystric.java

@Component
public class SchedualServiceHiHystric implements SchedualServiceHi {
    @Override
    public String sayHiFromClientOne(String name) {
        return "sorry "+name;
    }
}

Step 3-2:改造 SchedualServiceHi.java ,增加 fallback = 

package com.learn.feign.clients;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(value = "service-hi",fallback = SchedualServiceHiHystric.class))
public interface SchedualServiceHi {
    @RequestMapping(value = "/hi",method = RequestMethod.GET)
    String sayHiFromClientOne(@RequestParam(value = "name") String name);
}

 

浏览器交替显示:

hi forezp,i am from port:8762

hi forezp,i am from port:8763

浏览器显示:

sorry forezp

   

 

 
posted @ 2019-08-14 12:07  随风落木  阅读(0)  评论(0编辑  收藏  举报  来源