feign hystrix 熔断器的 fallback 类的熔断方法异常触发,及查看异常方法

明明正常调用生产者方法执行成功了,但是熔断器还会触发,时不时的就触发一次,折腾了一下午,终于发现原因:

 

应用启动后就立即执行了方法,应该稍微等待,等它完全运行

 

另外:查看降级熔断原因,使用fallbackfactory自带的create方法

@FeignClient(name = "service-vod",fallbackFactory = VodFallbaclFactory.class)
@Component
public interface VodConsumer {

    @DeleteMapping("/service-vod/video/{id}")
    public R removeVideoById(@PathVariable("id") String id);

    @DeleteMapping("/id/list")
    public R removeVideoByIds(@RequestBody List idList);
}

 

@Component
public class VodFallbaclFactory implements FallbackFactory {
    @Override
    public VodConsumer create(Throwable throwable) {
        return new VodConsumer() {
            @Override
            public R removeVideoById(String id) {
                System.out.println("removeById:" + throwable.getStackTrace() + throwable.getMessage() + throwable.fillInStackTrace());
                return null;
            }

            @Override
            public R removeVideoByIds(List idList) {
                return null;
            }
        };
    }
}

注意:@FeignClient 加上fallbackfactory后,不要再使用fallback,不然会优先fallback,无法查看异常

 

你可能感兴趣的:(springcloud,分布式开发,分布式开发,feign,hystrix,hystrix,fallback,熔断原因,fallback,异常熔断,fallback异常触发)