zrlw edited a comment on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-904321568


   更新: 下面所列方法实测无效!高并发场景下RpcContext的context会被其他线程覆盖掉,导致分支判断错误! 
保留下列内容只是为了讨论为啥会覆盖,debug跟踪发现两个执行回调方法的dubbo线程居然使用了同一个rpcContext,如截图所示,经调试确认是普通线程复用了尚未完成dubbo异步回调处理的rpcContext,我去另外开一个issue。
   ![dubbo threads share 
rpccontext](https://user-images.githubusercontent.com/40652892/130768145-83d254be-53a8-4f91-90ce-8d9114a055bc.png)
   
   ![dubbo threads share 
rpccontext2](https://user-images.githubusercontent.com/40652892/130768631-4c997a8b-1b2a-4988-aa55-803e87b3d217.png)
   
   --------------------------------------- 无效的尝试方法BEGIN 
---------------------------------------------
   在DubboReference注解上加 
parameters参数,同一个服务接口不同的Reference注解定义不同的参数,比如定义一个process参数,clientA用proc-a, 
clientB用proc-b:
   ```
   ClientA.java:
   @DubboReference( async = true, parameters = {"process", "proc-a"}, ...)
   DubboService s;
   ...
   ClientB.java:
   @DubboReference( async = true,, parameters = {"process", "proc-b"}, ...)
   DubboService s;
   ```
   
clientA和clientB的回调方法放到统一的门面组件里,回调方法依据rpccontext的consumerUrl里取出process参数分别进行处理,比如:
   ```
   String process = 
RpcContext.getContext().getConsumerUrl.getParameter("process");
   switch (process) {
       case "proc-a": ....
       case "proc-b": ....
   }
   ```
   要从consumerUrl的parameters里取出DubboReference注解定义的process参数的原因如下:
   1. 如果DubboReference注解设置了async=true, 
无论consumerUrl还是url的parameters都有process参数,parameters里面的side属性值都是consumer;
   2. 
如果DubboReference注解里没设置async=true,那么只有oninvoke方法执行时获得的rpcContext的url还有process参数,url的parameters里面的side属性值还是consumer,其他两个回调方法onreturn和onthrow获得的rpcContext的url里面没有process参数,而且parameters里面的side属性值是provider,而consumerUrl里面有process参数,consumerUrl里的side属性也一直都是consumer。
   ----------------------------------------------- 无效的尝试方法内容 END 
------------------------------------------------
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org
For additional commands, e-mail: notifications-h...@dubbo.apache.org

Reply via email to