搭建springcloud微服务(四)熔断器Hystrix

springcloud-account 微服务的controller增加HystrixCommand注解

MyController  

@RestController
public class MyController {
    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/a2b")
    @HystrixCommand(fallbackMethod = "hystrixFallback", commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000"),
            @HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "1000"),})
    public String memTest() {
        String str = restTemplate.getForObject("http://bill-server/billTest", String.class);
        return str;
    }
    public String hystrixFallback() {
        return "this is hystrixFallback";
    }
}

最后结果:调用失败后就调用默认方法返回。

熔断器Hystrix完毕!

猜你喜欢

转载自blog.csdn.net/x18094/article/details/114801524