Giter Club home page Giter Club logo

demo-seata-springcloud's Introduction

Hi there 👋

Anurag's github stats

demo-seata-springcloud's People

Contributors

sly1311220942 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

demo-seata-springcloud's Issues

结贴

你好,按照楼主所说,修改了seata源码,并在业务层加上feign拦截器,但我远程调用的时候,这个feign拦截器获取不了seata的xid,我的 springcloud版本Greenwich.SR1,我有自定义FeignHystrix并发策略,代码如下,是否这个影响了获取xid

public class FeignHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy {

private static final Logger log = LoggerFactory.getLogger(FeignHystrixConcurrencyStrategy.class);
private HystrixConcurrencyStrategy delegate;

public FeignHystrixConcurrencyStrategy() {
	try {
		this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy();
		if (this.delegate instanceof FeignHystrixConcurrencyStrategy) {
			// Welcome to singleton hell...
			return;
		}
		HystrixCommandExecutionHook commandExecutionHook =
			HystrixPlugins.getInstance().getCommandExecutionHook();
		HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier();
		HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher();
		HystrixPropertiesStrategy propertiesStrategy =
			HystrixPlugins.getInstance().getPropertiesStrategy();
		this.logCurrentStateOfHystrixPlugins(eventNotifier, metricsPublisher, propertiesStrategy);
		HystrixPlugins.reset();
		HystrixPlugins.getInstance().registerConcurrencyStrategy(this);
		HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
		HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
		HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
		HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
	} catch (Exception e) {
		log.error("Failed to register Sleuth Hystrix Concurrency Strategy", e);
	}
}

private void logCurrentStateOfHystrixPlugins(HystrixEventNotifier eventNotifier,
											 HystrixMetricsPublisher metricsPublisher, HystrixPropertiesStrategy propertiesStrategy) {
	if (log.isDebugEnabled()) {
		log.debug("Current Hystrix plugins configuration is [" + "concurrencyStrategy ["
			+ this.delegate + "]," + "eventNotifier [" + eventNotifier + "]," + "metricPublisher ["
			+ metricsPublisher + "]," + "propertiesStrategy [" + propertiesStrategy + "]," + "]");
		log.debug("Registering Sleuth Hystrix Concurrency Strategy.");
	}
}

@Override
public <T> Callable<T> wrapCallable(Callable<T> callable) {
	RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
	return new WrappedCallable<>(callable, requestAttributes);
}

@Override
public ThreadPoolExecutor getThreadPool(HystrixThreadPoolKey threadPoolKey,
										HystrixProperty<Integer> corePoolSize, HystrixProperty<Integer> maximumPoolSize,
										HystrixProperty<Integer> keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) {
	return this.delegate.getThreadPool(threadPoolKey, corePoolSize, maximumPoolSize, keepAliveTime,
		unit, workQueue);
}

@Override
public ThreadPoolExecutor getThreadPool(HystrixThreadPoolKey threadPoolKey,
										HystrixThreadPoolProperties threadPoolProperties) {
	return this.delegate.getThreadPool(threadPoolKey, threadPoolProperties);
}

@Override
public BlockingQueue<Runnable> getBlockingQueue(int maxQueueSize) {
	return this.delegate.getBlockingQueue(maxQueueSize);
}

@Override
public <T> HystrixRequestVariable<T> getRequestVariable(HystrixRequestVariableLifecycle<T> rv) {
	return this.delegate.getRequestVariable(rv);
}

static class WrappedCallable<T> implements Callable<T> {
	private final Callable<T> target;
	private final RequestAttributes requestAttributes;

	public WrappedCallable(Callable<T> target, RequestAttributes requestAttributes) {
		this.target = target;
		this.requestAttributes = requestAttributes;
	}

	@Override
	public T call() throws Exception {
		try {
			RequestContextHolder.setRequestAttributes(requestAttributes);
			return target.call();
		} finally {
			RequestContextHolder.resetRequestAttributes();
		}
	}
}

}

运行有误

楼主好,运行你的代码,在feign拦截器RequestInterceptor里面,String xid = RootContext.getXID();为null,得不到seata的xid,这是怎么回事?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.