需要使用断路器的项目之一,并使用hystrix的目的。但hystrix回退即使在超时后也不会触发。如果遗漏了什么,请帮助我们。提前谢谢你。
https://github.com/Netflix/Hystrix/tree/master/hystrix-contrib/hystrix-javanica
public class TestHystrix {
@HystrixCommand(fallbackMethod="fallbackCallFunc",
commandProperties={
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "500")
})
public String callFunc() throws InterruptedException{
Thread.sleep(1050);
return "success";
}
public String fallbackCallFunc(){
return "default";
}
public static void main(String[] args) throws InterruptedException {
ConfigurationManager.getConfigInstance().setProperty("hystrix.command.callFunc.execution.isolation.thread.timeoutInMilliseconds", "500");
TestHysterix testClass = new TestHysterix();
System.out.println(testClass.callFunc());
}
}发布于 2020-03-22 02:34:19
要让拦截器注释( HystrixCommand )工作,您需要将Interceptor()模块添加到服务代码中。
面向方面的编程功能。
工作:请注意,这里将使用方法拦截器来检测被调用的方法是否带有HystrixCommand注释,从而执行hystrix代码。
发布于 2018-01-10 17:16:38
您需要为您的项目配置Javanica。javanica wiki上有相关说明
要在Spring Boot中使用Javanica,您可以在以下位置找到简短指南
https://stackoverflow.com/questions/47095370
复制相似问题