在Hystrix做熔断的时候,开始用的是FallBack,后来为了找出为啥exception,然后就用了FallBackFactory。

但是奇怪的是,一起动就抛出异常,真的是百思不得骑姐,错了其解。

后来在github上找到了解答:

https://github.com/spring-cloud/spring-cloud-netflix/issues/1471

正确的打日志的策略:

/**
 * @author tuhooo
 */
@Component
public class RemoteDemoServiceHystrixFallBackFactory implements FallbackFactory<RemoteDemoService> {

    private final Logger logger = LoggerFactory.getLogger(SensetimeServiceHystrixFallBackFactory.class);

    @Override
    public RemoteDemoService create(Throwable throwable) {

        // 不要在这里打日志
        return new RemoteDemoService() {
            @Override
            public Result getFaceAttributes(String name) {
                // 在这里打日志
            }
        };
    }
}

还有代码要写,我就不深究原因了,反正我也只是用一下Spring Cloud。

05-13 11:41