dubbo-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] gougouzcm opened a new issue #1669: How can I know where I am called in a Router
Date Tue, 24 Apr 2018 09:15:40 GMT
gougouzcm opened a new issue #1669: How can I know where I am called in a Router
URL: https://github.com/apache/incubator-dubbo/issues/1669
 
 
   I write a router .
   ```
   @Override
       public <T> List<Invoker<T>> route(List<Invoker<T>> list,
URL url, Invocation invocation) throws RpcException {
   
   
           // TODO 不能这么决定是 zkSubscribe 的触发的route
           if (StringUtils.isBlank(invocation.getMethodName())){
   
               logger.info("zkRefresh notify invokes " + list);
               // 代表是 zk监听的触发的 refresh
               return list;
   
           }
   
           // 从ThreadLocal中拿到 当前的灰度分组
           String grayGroup = RpcGrayContext.getGrayGroup();
           if (StringUtils.isNotEmpty(grayGroup)){
               logger.info("current rpc request is  greyGroup " + grayGroup);
               invocation.getAttachments().put(Constant.GRAY_GROUP_KEY, grayGroup);
   
           }else {
               logger.info("current rpc request is  normalGroup " );
           }
   
   
   
           List<Invoker<T>> invokerList = new ArrayList<>();
   
           List<Invoker<T>> normalInvokerList = new ArrayList<>();
   
   
           if ( list != null ){
   
               for ( Invoker invoker : list ){
   
                   URL providerUrl = invoker.getUrl();
                   String providerGroup = providerUrl.getParameter(com.alibaba.dubbo.common.utils.StringUtils.camelToSplitName("dynamicGroup","."));
   
                   if (StringUtils.isBlank(providerGroup) ){
   
                       normalInvokerList.add(invoker);
                       System.out.println(providerUrl.getHost() + " is not AB test");
   
                       if (StringUtils.isBlank(grayGroup)) {
   
                           invokerList.add(invoker);
                       }
                   }else {
                       System.out.println(providerUrl.getHost() + " is  AB test , group is
" + providerGroup );
                       if ( providerGroup.equals(grayGroup) ){
                           invokerList.add(invoker);
                       }
   
                   }
   
   
               }
           }
           if (StringUtils.isNotBlank(grayGroup) && CollectionUtils.isEmpty(invokerList)){
               // 如果当前请求是灰度请求,但是没有任何灰度机器,那么按照正常的机器请求
               return normalInvokerList;
           }else {
               return invokerList;
   
           }
   
       }
   ```
   
   In this router , I want every rpc request route by  the  threadLocal `RpcGrayContext.getGrayGroup();`
content.
   If current rpc is a GrayGroup rpc ,I will found all the providers in this group.
   
   The question is that [RegistyDirctory](https://github.com/apache/incubator-dubbo/blob/master/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/integration/RegistryDirectory.java)
 will cache a map `Map<String, List<Invoker<T>>> methodInvokerMap`.
   It will call the method I Override 
   ```
   private List<Invoker<T>> route(List<Invoker<T>> invokers, String
method) {
               Invocation invocation = new RpcInvocation(method, new Class<?>[0], new
Object[0]);
               List<Router> routers = getRouters();
               if (routers != null) {
                   for (Router router : routers) {
                       if (router.getUrl() != null) {
                           invokers = router.route(invokers, getConsumerUrl(), invocation);
                       }
                   }
               }
               return invokers;
           }
   ```
   But when registry refresh the router or providers , the content from `RpcGrayContext.getGrayGroup()`
will be empty.
   It will cause the cachemap `methodInvokerMap` lost some InvokeUrl .
   
   So , If I know the my router was called by the ZkNotifyThread , I will return all the invokers.
   If my router was call by the rpc request , I will allocate the right grayGroup providersfrom
ThreadLocal  for this request .
   
   I don't want to use the `new Throwable().getStackTrace()` . 
   
   can any one help me ,thk
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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


Mime
View raw message