Get failure exception in @HystrixCommand fallback method

后端 未结 5 1312
-上瘾入骨i
-上瘾入骨i 2020-12-28 08:21

Is there a way to get the reason a HystrixCommand failed when using the @HystrixCommand annotation within a Spring Boot application? It looks like

5条回答
  •  温柔的废话
    2020-12-28 09:07

    I haven't found a way to get the exception with Annotations either, but creating my own Command worked for me like so:

    public static class DemoCommand extends HystrixCommand {
    
        protected DemoCommand() {
            super(HystrixCommandGroupKey.Factory.asKey("Demo"));
        }
    
        @Override
        protected String run() throws Exception {
            throw new RuntimeException("failed!");
        }
    
        @Override
        protected String getFallback() {
            System.out.println("Events (so far) in Fallback: " + getExecutionEvents());
            return getFailedExecutionException().getMessage();
        }
    
    }
    

    Hopefully this helps someone else as well.

提交回复
热议问题