feign:
hystrix:
enabled: true
二、基于前面第三步中feign_test工程进行改造,只需要在IHiService接口的注解中加上fallback的指定类就行了
@FeignClient(value = “serviceHii” ,fallback = HiServiceHystric.class)
public interface IHiService {
@RequestMapping(value = “/hi”,method = RequestMethod.GET)
String sayHii(@RequestParam(value = “name”) String name);
}
三、新增HiServiceHystric实现类,需要实现IHiServcie接口
@Component
public class HiServiceHystric implements IHiService {
@Override
public String sayHii(String name) {
return “Sorry,”+name+”,server is disconnect!”;
}
}
四、关闭服务提供者serverHi工程,启动feign_test工程,浏览器打开http://localhost:8765/hello?name=czy,网页显示:
Sorry,czy,server is disconnect!
打开service-hi工程,再次访问,浏览器显示:
hi czy(from port:7072)
这就证明断路器起作用了。