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!