接上一篇的文章,若是这个时候把2个Computer服务都关闭,调用的结果以下:java
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Fri Dec 02 10:44:06 CST 2016 There was an unexpected error (type=Internal Server Error, status=500). add timed-out and no fallback available.
咱们不须要在Feigh工程中引入Hystix,Feign中已经依赖了Hystrixweb
使用@FeignClient注解中的fallback属性指定回调类spring
package i.a.c; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; @FeignClient(value = "compute-service", fallback = ComputeClientHystrix.class) public interface ComputeClient { @RequestMapping(method = RequestMethod.GET, value = "/add") Integer add(@RequestParam(value = "a") Integer a, @RequestParam(value = "b") Integer b); }
报错是由于目前尚未ComputeClientHystrix.class类app
补上ide
建立回调类ComputeClientHystrix,实现@FeignClient的接口,此时实现的方法就是对应@FeignClient接口中映射的fallback函数。函数
package i.a.c; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.RequestParam; @Component public class ComputeClientHystrix implements ComputeClient { @Override public Integer add(@RequestParam(value = "a") Integer a, @RequestParam(value = "b") Integer b) { return -9999; } }
再重试下,结果是什么?this