简体   繁体   中英

Circuit Breaker does not work when a method annotated with HystrixCommand calls another method which throws exception

I have an abstract class

public abstract class A {
    public String makeSomething(String ingredients){
        throw new RuntimeException("Can't Make anything");
    }
}

This class is realised in another class B(Spring Service) which uses makeSomething in many of its own methods by passing Ingredients. Each method in class B is annotated with HystrixCommand and a fallback has been defined for it. Here is what it looks like

@Service
public class B extends A {    
    @HystrixCommand(fallbackMethod = "doNothing")
    public void makeTea(String ingredients){
        makeSomething(ingredients);
    }

    public void doNothing(String ingredients){
        System.out.println("Doing Nothing");
    }

}

Now when makeTea from class B is invoked, it inturn calls makeSomething from class A which then throws exception. This should be wrapped as HystrixRuntimeException and then fallback should be invoked. But I am seeing RunTimeException("Can't Make anything").

Based on your description, I would say, Hystrix is not enabled.

Add @EnableHystrix annotation to your Application class, so annotation processing is enabled.

If you have it enabled, please provide a more complete example, where the error can be reproduced.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM