servicecomb-java-chassis icon indicating copy to clipboard operation
servicecomb-java-chassis copied to clipboard

升级到2.6.0版本发现filter逻辑是在网络线程,不是在业务线程,如果业务通过扩展filter获取业务线程上下文,当前2.6版本之后无法获取

Open yanghao605 opened this issue 3 years ago • 4 comments

https://github.com/apache/servicecomb-java-chassis/blob/703a972576b35154d9a9a46f087411fab86fd74a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/RestClientInvocation.java#L123

yanghao605 avatar Jun 30 '22 08:06 yanghao605

你这个获取的时候要在哪里获取呢,是下游微服务吗还是说后面的某个特定位置。

lbc97 avatar Jul 06 '22 01:07 lbc97

能给看一下你是如何在filter里面获取上下文并添加内容的吗?

lbc97 avatar Jul 06 '22 01:07 lbc97

我这里直接是可以取到框架的上下文的。

lbc97 avatar Jul 06 '22 02:07 lbc97

是在业务线程中设置ThreadLocal数据,在Filter中无法获取到数据。 @RequestMapping(value = "/user", method = RequestMethod.GET) public String userInfo(@RequestParam(value = "name", required = true) String name) {

    ContextInterceptor.setContextCachethreadLocal(10000989);

…… public class ContextInterceptor {

private static final ThreadLocal<Integer> threadLocal = new ThreadLocal<>();

…… public class CseTest implements HttpClientFilter {

@Override
public int getOrder() {
    return 0;
}

@Override
public void beforeSendRequest(Invocation invocation, HttpServletRequestEx requestEx) {

    System.out.println("threadLocal=" + ContextInterceptor.getContextCachethreadLocal());

这里获取为空

yanghao605 avatar Jul 11 '22 01:07 yanghao605

Add a PR to use async implicitly. see https://github.com/apache/servicecomb-java-chassis/pull/3291/files

liubao68 avatar Aug 21 '22 14:08 liubao68