spring hystrix 随笔

阅读更多

hystrix 是一个断路器,可以进行熔断等功能。

最简单的demo:

@RestController
@EnableCircuitBreaker
public class MainController {

	@RequestMapping("/fun")
	@HystrixCommand(fallbackMethod="gun")
	public String fun(@RequestParam String s){
		System.out.println("in fun---");
		if("error".equals(s)){
			throw new RuntimeException("err");
		}
		return "ok";
	}
	

	public String gun(String s){
		System.out.println("in gun ***");
		return "gun"+s;
	}
	
}

 

通过Application类 启动后,即可访问:localhost:9999/fun?s=jcos

将返回 ok

如果s=error,则返回 gunerror。可见,fallback 生效了。

 

 

你可能感兴趣的:(spring hystrix 随笔)