跳到主要内容

5、Hystrix 应用问题

1、 问题总结;

如果项目中使用了ThreadLocal,注意hystix创建新线程时,ThreadLocal中存的是之前线程中的数据,在hystix线程中获取不到

2、 问题;

throwable异常参数必须写在最后边
   public String getText(long liveId,int sdkId,Throwable throwable) {
        if (throwable instanceof HystrixTimeoutException) {
            logger.error("m={} is fusing;request={};ex={}", "getLiveVideoDependInfofallBack", JSON.toJSONString(request), "timeout");
        }else {
            logger.warn("m={} is fusing;request={}", "getLiveVideoDependInfofallBack", JSON.toJSONString(request));
        }
        return liveVideoInfoResponse;
    }

3、 springboot启动类添加EnableHystrix开启Hystrix;

@SpringBootApplication
@ImportResource("classpath:spring-*.xml")
@EnableHystrix
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

4、 异步注解方式时,注意要覆盖get方法;

@Override
            public GetLiveVideoInfoResponse get() {
                return invoke();
            }