断路器Hystrix(基于fein)"/>
spring cloud第四步: 断路器Hystrix(基于fein)
一、Feign是自带断路器的,只需在yml配置文件加以下代码: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!
hi czy(from port:7072)
更多推荐
spring cloud第四步: 断路器Hystrix(基于fein)
发布评论