zipkin使用hystrix无法串联起调用链的解决方法

在使用zipkin的过程,引用hystrix导致调用链条break,原来hystrix默认容错方法是线程隔离,而在这个过程中使用了线程池,而线程池中的traceId无法重新生成,导致调用链断掉,因此重写HystrixConcurrencyStrategy 类的wrapCallable即可达到修复效果,代码如下:

@Component
public class TracingHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy {
    @Autowired
    private Tracing tracing;

    public TracingHystrixConcurrencyStrategy(){
        HystrixPlugins.reset();
        HystrixPlugins.getInstance().registerConcurrencyStrategy(this);
    }

    @Override
    public  Callable wrapCallable(Callable callable) {
        CurrentTraceContext context = tracing.currentTraceContext();
        if(context!=null)
            return context.wrap(callable);
        else
            return super.wrapCallable(callable);
    }

    public void setTracing(Tracing tracing) {
        this.tracing = tracing;
    }
}

你可能感兴趣的:(零星)