一, Feign是自带断路器的
feign.hystrix.enabled=true 是否开启熔断器
hystrix.command.default.execution.timeout.enabled=true 是否开启超时熔断, 如果为false, 则熔断机制只在服务不可用时开启
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=300 设置超时熔断时间
[java] view plain copy
@FeignClient(value = "YunCai-SearchServer", fallback=ServiceHystrix.class)
public interface SchedualServiceHi {
@RequestMapping(value = "/luke/itemsearch",method = RequestMethod.GET)
ResponseMap sayHiFromClientOne(@RequestParam(value = "start") Integer start,
@RequestParam(value = "rows") Integer rows,
@RequestParam(value = "tenantId") Integer tenantId,
@RequestParam(value = "status") Integer status,
@RequestParam(value = "key") String key);
}
[java] view plain copy
public class ServiceHystrix implements SchedualServiceHi {
public ResponseMap sayHiFromClientOne(Integer start, Integer rows, Integer tenantId, Integer status, String key) {
SearchResult result = new SearchResult(0, new ArrayList<>(Arrays.asList(1L,2L,3L)));
return new ResponseMap(false, "111", 506, result);
}
}
二, Hystrix 仪表盘
首选在pom.xml引入spring-cloud-starter-hystrix-dashboard的起步依赖:
[java] view plain copy
在主程序启动类中加入@EnableHystrixDashboard注解,开启hystrixDashboard:
[java] view plain copy
public class ServiceRibbonApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceRibbonApplication.class, args);
}
RestTemplate restTemplate() {
return new RestTemplate();
}
}
打开浏览器:访问http://localhost:8764/hystrix,界面如下:
点击monitor stream,进入下一个界面,访问:http://localhost:8764/hi?name=forezp
此时会出现监控界面:
手机扫一扫
移动阅读更方便
你可能感兴趣的文章