码迷,mamicode.com
首页 > 其他好文 > 详细

hystrix 给方法加断路器

时间:2017-06-20 13:33:20      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:pen   exception   char   void   ase   --   run   str   group   

 

添加依赖

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>

1.启动类

@SpringBootApplication
@EnableDiscoveryClient
@ComponentScan("Cloud_Hystrix.*")
@EnableCircuitBreaker
public class HystrixController {
public static void main(String[] args) {
SpringApplication.run(HystrixController.class, args);
}
}

 

 

2,controller

@RestController
@RequestMapping(value="/reqmap",produces={"application/json;charaset=utf-8"},method=RequestMethod.GET)
public class HystrixReqMap {
@Autowired
HystrixService hystrixService;
@RequestMapping("")
public String reqmap(String param){
return hystrixService.reqmap(param);
}
}

 

 

3.service

@Service
public class HystrixService {
@HystrixCommand(fallbackMethod="fail")
public String reqmap(String param){
if(param.equals("aaa")){
throw new RuntimeException();
}
return param+"--hystrix";
}
public String fail(String param){
return "runtimeException";
}
}

hystrix 给方法加断路器

标签:pen   exception   char   void   ase   --   run   str   group   

原文地址:http://www.cnblogs.com/wangjing666/p/7053691.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!