hystrix 应用问题

博客总结了项目中使用ThreadLocal和Hystrix的相关问题。使用ThreadLocal时,Hystrix创建新线程会导致获取不到之前线程中ThreadLocal存的数据;Spring Boot启动类需添加EnableHystrix开启Hystrix;异步注解方式时要覆盖get方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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();
            }

 

转载于:https://www.cnblogs.com/liyongliang/p/10948845.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值