Build springcloud microservice (4) Hystrix fuse

The controller of springcloud-account microservice adds HystrixCommand annotation

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";
    }
}

The final result: After the call fails, the default method is called to return.

Hystrix fuse is over!

Guess you like

Origin blog.csdn.net/x18094/article/details/114801524