You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/08/22 12:43:38 UTC

[GitHub] [dubbo] zrlw opened a new issue #8567: 多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

zrlw opened a new issue #8567:
URL: https://github.com/apache/dubbo/issues/8567


   ### Environment
   * Dubbo version: 2.7.13
   * Operating System version: centos7
   * Java version: 1.8
   * nacos 1.4.2
   
   ### Steps to reproduce this issue
   一个springboot工程里有两个组件ClientA, ClientB,分别reference了同一个dubbo服务S,调用S的方法execute分别设置了不同的回调方法:
   ```
   @Component
   public class ClientA {
        // 回调组件callbackA
       @DubboReference( async = true, methods = @Method(name = "execute", onreturn = "callbackA.onReturn"))
       DubboService s;
   
       public void callS(...) {
           s.execute(...);
       }
   }
   
   @Component
   public class CallbackA {
       public void onReturn(...) {
       }
   }
   
   @Component
   public class ClientB {
        // 回调组件callbackB
       @DubboReference( async = true, methods = @Method(name = "execute", onreturn = "callbackB.onReturn"))
       DubboService s;
   
       public void callS(...) {
           s.execute(...);
       }
   }
   
   @Component
   public class CallbackB {
       public void onReturn(...) {
       }
   }
   ```
   
   ### Expected Result
   ClientA调用S的execute方法返回后,回调CallbackA的onReturn,ClientB调用S的execute方法返回后,回调CallbackB的onReturn。
   
   ### Actual Result
   无论ClientA,还是ClientB,调用S的execute方法后,始终只调用CallbackA或CallbackB中的一个onReturn方法(具体调用哪个貌似和加载顺序有关)。
   


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw commented on issue #8567: 多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw commented on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-903290113


   1. FutureFilter的fireInvokeCallback,fireReturnCallback,fireThrowCallback方法调用getAsyncMethodInfo:从ServiceRepository的ConcurrentMap保存的consumerModel取出AsyncMethodInfo,其中ConcurrentMap的key值是invoke url中的interfaceName, group, version组合。如果有AsyncMethodInfo,就进行回调。
   2. ReferenceConfig的init方法调用checkAndUpdateSubConfigs方法,然后调用ServiceRepository的registerConsumer方法注册consumerModel的时候,传入的serviceKey只是interfaceName, group, version,不包含methods属性参数,同一个dubbo接口的多个ReferenceBean注册的consumerModel的serviceKey相同,因此只有最后一个才得到保留。
   如果是上述代码导致的,那么serviceKey需要加入ReferenceBean的id或者名称。
   PS:
   之所以搞多个Reference bean,是因为看到有帖子说dubbo2.7.4开始就支持注册同一接口的多个Reference bean了:
   https://www.cnblogs.com/tlj2018/articles/12198391.html


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw edited a comment on issue #8567: [2.7.13]多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw edited a comment on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-907038955


   增加自定义的filter可能搞不定,现在的ReferenceConfig对于同一个dubbo接口不同的引用只保存最后引用的AsyncMethodInfo,增加自定义Filter也只能取出来最后引用对应的AsyncMethodInfo。
   我们现在把几个回调类做了合并,每个Reference上配置了不同parameter参数,在回调方法里依据rpcContext里consumerURL的参数进行区分处理,为了应对随之而来的问题: #8602  
   我们修改了发起异步调用dubbo服务的应用代码,每次异步调dubbo服务都单独新建一个线程里发起,后面这个问题涉及到RpcContext的设计框架,感觉可能更不容易修复。


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw commented on issue #8567: [2.7.13]多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw commented on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-907038955


   增加自定义的filter可能搞不定,现在的ReferenceConfig对于同一个dubbo接口不同的引用只保存最后引用的AsyncMethodInfo,增加自定义Filter也只能取出来最后引用对应的AsyncMethodInfo。
   我们现在把几个回调类做了合并,每个Reference上配置了不同parameter参数,在回调方法里依据rpcContext里consumerURL的参数进行区分处理,为了应对随之而来的 #8602, 每个异步调dubbo服务都是在单独新建的线程里发起。
   后面这个问题涉及到RpcContext的设计框架,感觉更不容易修改。


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw commented on issue #8567: 多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw commented on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-903497831


   提交的PR将asyncMethodInfo map的JSON串对应的hashcode拼到原来的serviceKey后面作为保存consumerModel的consumer map的entry key了,因为asyncMethodInfo map的JSON串太长了,换成了hash值了,否则url长度会暴涨。


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw edited a comment on issue #8567: [2.7.13]多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw edited a comment on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-904321568


   也可以变通一下解决这个问题:
   在DubboReference注解上加 parameters参数,同一个服务接口不同的Reference注解定义不同的参数,比如定义一个process参数,clientA用proc-a, clientB用proc-b:
   ```
   ClientA.java:
   @DubboReference( parameters = {"process", "proc-a"}, ...)
   DubboService s;
   ...
   ClientB.java:
   @DubboReference( parameters = {"process", "proc-b"}, ...)
   DubboService s;
   ```
   clientA和clientB的回调回调方法放到统一的门面组件里,回调方法依据rpccontext的url里取出process参数分别进行处理,比如:
   ```
   String process = RpcContext.getContext().getUrl.getParameter("process");
   switch (process) {
       case "proc-a": ....
       case "proc-b": ....
   }
   ```


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw closed issue #8567: [2.7.13]多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw closed issue #8567:
URL: https://github.com/apache/dubbo/issues/8567


   


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw edited a comment on issue #8567: [2.7.13]多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw edited a comment on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-904321568


   也可以变通一下解决这个问题:
   在DubboReference注解上加 parameters参数,同一个服务接口不同的Reference注解定义不同的参数,比如定义一个process参数,clientA用proc-a, clientB用proc-b:
   ```
   ClientA.java:
   @DubboReference( parameters = {"process", "proc-a"}, ...)
   DubboService s;
   ...
   ClientB.java:
   @DubboReference( parameters = {"process", "proc-b"}, ...)
   DubboService s;
   ```
   clientA和clientB的回调方法放到统一的门面组件里,回调方法依据rpccontext的url里取出process参数分别进行处理,比如:
   ```
   String process = RpcContext.getContext().getUrl.getParameter("process");
   switch (process) {
       case "proc-a": ....
       case "proc-b": ....
   }
   ```


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw edited a comment on issue #8567: [2.7.13]多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw edited a comment on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-912434704


   经验证测试,昨天3.0分支提交的多实例PR满足多个reference同一接口分别设置不同回调方法的需求,粗略看了一下代码,大致处理过程如下:
   1. ReferenceConfig的init方法首先为每一个Reference创建一个consumerModel, 每个consumerModel里面的methodConfigs保存了各自配置的onXXX回调方法;然后调用createProxy方法创建代理时,将consumerModel存入了代理对象的handler的serviceModel属性;
   2. 回调处理时,从调用使用的handler的serviceModel取出methodConfigs,里面就有Reference注解的回调方法。
   @chickenlj  期待早日更新2.7.X!


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] AlbumenJ commented on issue #8567: [2.7.13]多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
AlbumenJ commented on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-906944092


   > > 从我个人理解来看,社区不能接收 #8574 的改法,增加异步方法配置的hashcode是一个非常定制化的解决方案,我们需要一个更通用的解决方案,3.0 中的多实例会是一个很好的参考,让我们先等待那边的具体实现。
   > 
   > 很期待社区提供整体解决方案,大概要等多久发布?
   > 如果多实例方案里还保留有consumer model map,那么entry key还是需要进行修订吧,只是用async method的hash code的确过于定制化,我们重新提交了PR修改内容,把entry key改为了serviceKey和attribute hashcode的组合,attribute就是consumer model对象中的methodConfigs属性,还请各位复核一下这样做是否通用一些。
   > 如果这个改法也不通用,并且整体解决方案要等一个月以上,可否提供一些整体解决的具体思路,我们可能要先行定制化一下解决这个问题,但是还想尽可能保证和今后发布的整体方案保持兼容性,以便以后升级dubbo版本。
   > @chickenlj
   
   社区的多实例方案可能还需要一段时间,短期的话你们也可以使用自定义 Filter 去实现


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw edited a comment on issue #8567: [2.7.13]多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw edited a comment on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-904321568


   也可以变通一下解决这个问题:
   在DubboReference注解上加 parameters参数,同一个服务接口不同的Reference注解定义不同的参数,比如定义一个process参数,clientA用proc-a, clientB用proc-b:
   ```
   ClientA.java:
   @DubboReference( parameters = {"process", "proc-a"}, ...)
   DubboService s;
   ...
   ClientB.java:
   @DubboReference( 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": ....
   }
   ```


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw commented on issue #8567: [2.7.13]多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw commented on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-905092983


   > 从我个人理解来看,社区不能接收 #8574 的改法,增加异步方法配置的hashcode是一个非常定制化的解决方案,我们需要一个更通用的解决方案,3.0 中的多实例会是一个很好的参考,让我们先等待那边的具体实现。
   
   很期待社区提供整体解决方案,大概要等多久发布?
   如果多实例方案里还保留有consumer model map,那么entry key还是需要进行修订吧,只是用async method的hash code的确过于定制化,我们重新提交了PR修改内容,把entry key改为了serviceKey和attribute hashcode的组合,attribute就是consumer model对象中的methodConfigs属性,还请各位复核一下这样做是否通用一些。
   如果这个改法也不通用,并且整体解决方案要等一个月以上,可否提供一些整体解决的具体思路,我们可能要先行定制化一下解决这个问题,但是还想尽可能保证和今后发布的整体方案保持兼容性,以便以后升级dubbo版本。
   @chickenlj 


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw commented on issue #8567: [2.7.13]多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw commented on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-904321568


   也可以变通一下解决这个问题:
   在DubboReference注解上加 parameters参数,同一个服务接口不同的Reference注解定义不同的参数,比如定义一个process参数,clientA用proc-a, clientB用proc-b:
   ```
   ClientA.java:
   @DubboReference( paramters = {"process", "proc-a"}, ...)
   DubboService s;
   ...
   ClientB.java:
   @DubboReference( paramters = {"process", "proc-b"}, ...)
   DubboService s;
   ```
   clientA和clientB的回调回调方法放到统一的门面组件里,回调方法依据rpccontext的url里取出process参数分别进行处理,比如:
   ```
   String process = RpcContext.getContext().getUrl.getParameter("process");
   switch (process) {
       case "proc-a": ....
       case "proc-b": ....
   }
   ```


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw edited a comment on issue #8567: [2.7.13]多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw edited a comment on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-912434704


   经验证测试,昨天3.0分支提交的多实例PR满足多个reference同一接口分别设置不同回调方法的需求,粗略看了一下代码,大致处理过程如下:
   1. ReferenceConfig的init方法首先为每一个Reference创建一个consumerModel, 每个consumerModel里面的methodConfigs保存了各自配置的onXXX回调方法;然后调用createProxy方法创建代理时,将consumerModel存入了代理对象的InvokerInvocationHandler的serviceModel属性;
   2. 调用接口方法时,InvokerInvocationHandler的invoke方法创建RpcInvocation把serviceModel存入RpcInvocation;
   3. 调用结束后,FutureFilter的fireXXXCallback方法调用getAsyncMethodInfo从RpcInvocation保存的serviceModel中的methodConfigs取得回调方法信息。
   
   @chickenlj  期待早日更新2.7.X!


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw edited a comment on issue #8567: [2.7.13]多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw edited a comment on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-912434704


   经验证测试,昨天3.0分支提交的多实例PR满足多个reference同一接口分别设置不同回调方法的需求,粗略看了一下代码,大致处理过程如下:
   1. ReferenceConfig的init方法首先为每一个Reference创建一个consumerModel, 每个consumerModel里面的methodConfigs保存了各自配置的onXXX回调方法;然后调用createProxy方法创建代理时,将consumerModel存入了代理对象的InvokerInvocationHandler的serviceModel属性;
   2. 调用接口方法时,InvokerInvocationHandler的invoke方法创建RpcInvocation把serviceModel存入RpcInvocation;
   3. 调用结束后,FutureFilter的fireXXXCallback方法调用getAsyncMethodInfo从RpcInvocation保存的serviceModel中的methodConfigs取得回调方法信息。
   @chickenlj  期待早日更新2.7.X!


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw edited a comment on issue #8567: [2.7.13]多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw edited a comment on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-907038955


   增加自定义的filter可能搞不定,现在的ReferenceConfig对于同一个dubbo接口不同的引用只保存最后引用的AsyncMethodInfo,增加自定义Filter也只能取出来最后引用对应的AsyncMethodInfo。
   我们现在把几个回调类做了合并,每个Reference上配置了不同parameter参数,在回调方法里依据rpcContext里consumerURL的参数进行区分处理,为了应对随之而来的问题: #8602  
   我们修改了发起异步调用dubbo服务的代码,每次异步调dubbo服务都单独新建一个线程里发起,后面这个问题涉及到RpcContext的设计框架,感觉可能更不容易修复。


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw edited a comment on issue #8567: [2.7.13]多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw edited a comment on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-904321568


   更新: 下面所列方法实测无效!高并发场景下RpcContext的context会被其他线程覆盖掉,导致分支判断错误! 保留下列内容只是为了说明!!! 2021.8.25
   
   --------------------------------------- 无效的尝试方法BEGIN ---------------------------------------------
   在DubboReference注解上加 parameters参数,同一个服务接口不同的Reference注解定义不同的参数,比如定义一个process参数,clientA用proc-a, clientB用proc-b:
   ```
   ClientA.java:
   @DubboReference( parameters = {"process", "proc-a"}, ...)
   DubboService s;
   ...
   ClientB.java:
   @DubboReference( 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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw edited a comment on issue #8567: [2.7.13]多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw edited a comment on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-904321568


   更新: 下面所列方法实测无效!高并发场景下RpcContext的context会被其他线程覆盖掉,导致分支判断错误! 保留下列内容只是为了讨论为啥会覆盖,感觉遇到了另外一个bug:debug跟踪发现两个执行回调方法的dubbo线程居然使用了同一个rpcContext,如截图所示。
   ![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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw edited a comment on issue #8567: [2.7.13]多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw edited a comment on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-904321568


   更新: 下面所列方法实测无效!高并发场景下RpcContext的context会被其他线程覆盖掉,导致分支判断错误! 保留下列内容只是为了讨论为啥会覆盖,感觉遇到了另外一个bug:debug跟踪发现两个执行回调方法的dubbo线程居然使用了同一个rpcContext,如截图所示。
   ![dubbo threads share rpccontext](https://user-images.githubusercontent.com/40652892/130768145-83d254be-53a8-4f91-90ce-8d9114a055bc.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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw commented on issue #8567: 多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw commented on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-903355704


   可否这样修订:
   1.  将init方法里生成AsyncMethodInfo map(attributes变量)的代码提到checkAndUpdateSubConfigs调用前,将attributes变量序列化后作为入参传入checkAndUpdateSubConfigs方法;
   2. 在checkAndUpdateSubConfigs方法repository.registerConsumer时,第一个入参由serviceMetadata.getServiceKey()改为serviceMetadata.getServiceKey()+attributes变量序列化串作为consumerModel map的key;
   3. 在init方法调用createProxy(map)前,将attributes变量序列化串放入map传入createProxy:在createProxy方法生成consumerURL时,入参map中的AsyncMethodInfo Map序列化串将保存到invoker的URL;
   4.  将所有调用ApplicationModel.getConsumerModel获取consumerModel的方法入参由serviceKey改为serviceKey+url里面保存的AsyncMethodInfo Map序列化串。
   大家看看如果这样做没有问题,我就去提交一个PR了。


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw edited a comment on issue #8567: [2.7.13]多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw edited a comment on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-904321568


   更新: 下面所列方法实测无效!高并发场景下RpcContext的context会被其他线程覆盖掉,导致分支判断错误! 保留下列内容只是为了讨论为啥会覆盖,感觉遇到了另外一个bug:debug跟踪发现两个执行回调方法的dubbo线程居然使用了同一个rpcContext,如截图所示。
   ![dubbo threads share rpccontext](https://user-images.githubusercontent.com/40652892/130768145-83d254be-53a8-4f91-90ce-8d9114a055bc.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 ------------------------------------------------
   ![dubbo threads share rpccontext2](https://user-images.githubusercontent.com/40652892/130768631-4c997a8b-1b2a-4988-aa55-803e87b3d217.png)
   


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] chickenlj commented on issue #8567: 多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
chickenlj commented on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-903506916


   从我个人理解来看,社区不能接收 https://github.com/apache/dubbo/pull/8574 的改法,增加异步方法配置的hashcode是一个非常定制化的解决方案,我们需要一个更通用的解决方案,3.0 中的多实例会是一个很好的参考,让我们先等待那边的具体实现。


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw edited a comment on issue #8567: [2.7.13]多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw edited a comment on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-904321568


   也可以变通一下解决这个问题:
   在DubboReference注解上加 parameters参数,同一个服务接口不同的Reference注解定义不同的参数,比如定义一个process参数,clientA用proc-a, clientB用proc-b:
   ```
   ClientA.java:
   @DubboReference( parameters = {"process", "proc-a"}, ...)
   DubboService s;
   ...
   ClientB.java:
   @DubboReference( 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。


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] AlbumenJ commented on issue #8567: 多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
AlbumenJ commented on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-903492482


   这个应该是多实例相关的问题,目前社区正在对这一块进行完整的重构,完成后会一次性解决相关的问题。
   https://www.yuque.com/apache-dubbo/dubbo3/wz70lz


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw commented on issue #8567: 多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw commented on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-903494843


   我们还需要继续用2.7.X,可能使用的时间还不会少于1年,所以更关注2.7系列的补丁计划。


-- 
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw edited a comment on issue #8567: [2.7.13]多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
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-unsubscribe@dubbo.apache.org

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



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


[GitHub] [dubbo] zrlw commented on issue #8567: [2.7.13]多个引用同一个接口的DubboReference分别设置不同的事件回调时,只会生效一个

Posted by GitBox <gi...@apache.org>.
zrlw commented on issue #8567:
URL: https://github.com/apache/dubbo/issues/8567#issuecomment-912434704


   昨天提交3.0分支的多实例PR经验证测试满足多个reference同一接口分别设置不同回调方法的需求,粗略看了一下代码,大致处理过程如下:
   1. ReferenceConfig的init方法首先为每一个Reference创建一个consumerModel, 每个consumerModel里面的methodConfigs保存了各自配置的onXXX回调方法;然后调用createProxy方法创建代理时,将consumerModel存入了代理对象的handler的serviceModel属性;
   2. 回调处理时,从调用使用的handler的serviceModel取出methodConfigs,里面就有Reference注解的回调方法。
   @chickenlj  期待早日更新2.7.X!


-- 
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-unsubscribe@dubbo.apache.org

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



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