您的位置:首页 > 编程语言 > Java开发

第十九章 springboot + hystrix(1)

2016-05-20 13:35 495 查看
hystrix是微服务中用于做熔断、降级的工具。

作用:防止因为一个服务的调用失败、调用延时导致多个请求的阻塞以及多个请求的调用失败。

1、pom.xml(引入hystrix-core包)

@RestController
@RequestMapping("/hotel")
@Api("HotelController相关api")
public class HotelController {
@ApiOperation("获取酒店Hotel信息:getHotelInfo")
@RequestMapping(value="/getHotelInfo",method=RequestMethod.GET)
public Hotel getHotelInfo(@RequestParam("id") int id, @RequestParam("name") String name) {
//        try {
//            TimeUnit.MILLISECONDS.sleep(2000);//用于测试超时
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
return new Hotel(id, name);
}
}


View Code
测试:启动被调用服务-->启动调用服务

参考:

http://blog.csdn.net/xiaoyu411502/article/details/50601687 官方的中文总结

https://stonetingxin.gitbooks.io/hystrix/content/ 基本上是官方的中文翻译

https://github.com/Netflix/Hystrix/wiki/Configuration hystrix配置介绍

http://blog.vicoder.com/hystrix-configuration/ 配置介绍

http://www.insaneprogramming.be/blog/2014/08/19/hystrix-spring-boot/ boot集成hystrix
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: