Hystrix有助于虚假容忍和延迟容忍。通过使用回退方法,我们可以显示空数据或该服务已关闭的一些消息,但如果MicroService1 id需要在其他业务逻辑中如何处理此问题?
MicroService1-这是我的示例代码
这是其他microservice2将调用的API。它需要返回一个String作为ID。
@RequestMapping(value = "/list")
public String list() {
return "Some Id";
}
@HystrixCommand(commandProperties = { @HystrixProperty(name = "execution.timeout.enabled", value = "true"),
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "500"),
@HystrixProperty(name = "fallback.enabled", value = "true")
}, fallbackMethod = "fallback", commandKey = "list", groupKey = "EmployeeServiceImpl")
public String list() {
RestTemplate restTemplate = new RestTemplate();
return restTemplate.getForObject(microservice1apiurl, String.class);
}
public String fallback() {
return "";
}