Reputation: 407
Need to use circuit breaker for one of the projects and using hystrix for the purpose. But hystrix fallback are not triggered even after timeouts. Please help if something is been missed. Thank you in advance.
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());
}
}
Upvotes: 0
Views: 1356
Reputation: 33
For HystrixCommand annotation(Javanica) to work, you need to add Interceptor() module to your service code.
[AOP - Aspect Oriented Programming] functionality.
Working: Please note here Method interceptor will be used to detect that if the method being called is annotated with HystrixCommand annotation and thereby hystrix code gets executed.
Upvotes: 2
Reputation: 243
You need to configure Javanica for your project. There are instructions on the javanica wiki
To use Javanica with Spring Boot you can find a short guide at
https://spring.io/guides/gs/circuit-breaker/
Upvotes: 1