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/11/05 07:10:19 UTC

[GitHub] [dubbo] bran2015 opened a new issue #9212: RegistryService#subscribe为和在服务导出时也要执行?

bran2015 opened a new issue #9212:
URL: https://github.com/apache/dubbo/issues/9212


   在2.7.8版本中,RegistryService#subscribe到入口为RegistryProtocol#export和RegistryProtocol#doRefer方法,前者为服务导出时调用,后者为服务引用是调用,RegistryProtocol#export方法处理过后的overrideSubscribeUrl格式为:provider://127.0.0.1:20880/com.example.DemoService?category=configurators&check=false&Xxxx=xxxx,当使用nacos作为注册中心时,该调用路径为:RegistryProtocol#export->ListenerRegistryWrapper#subscribe->FailbackRegistry#subscribe->NacosRegistry#doSubscribe->NacosRegistry#notifySubscriber->FailbackRegistry#notify->AbstractRegistry#notify.在这个调用链中,并没有发现有用信息,请问在服务导出时,为啥要调用RegistryService#subscribe方法?
   
   再看下AbstractRegistry#notify方法:
   ```
   protected void notify(URL url, NotifyListener listener, List<URL> urls) {
           if (url == null) {
               throw new IllegalArgumentException("notify url == null");
           }
           if (listener == null) {
               throw new IllegalArgumentException("notify listener == null");
           }
           if ((CollectionUtils.isEmpty(urls))
                   && !ANY_VALUE.equals(url.getServiceInterface())) {
               logger.warn("Ignore empty notify urls for subscribe url " + url);
               return;
           }
           if (logger.isInfoEnabled()) {
               logger.info("Notify urls for subscribe url " + url + ", urls: " + urls);
           }
           // 保留每个provider的category
           Map<String, List<URL>> result = new HashMap<>();
           for (URL u : urls) {
               if (UrlUtils.isMatch(url, u)) {
                   String category = u.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY);
                   List<URL> categoryList = result.computeIfAbsent(category, k -> new ArrayList<>());
                   categoryList.add(u);
               }
           }
           // 服务导出时的订阅,执行到此就结束了
           if (result.size() == 0) {
               return;
           }
           // 添加缓存
           Map<String, List<URL>> categoryNotified = notified.computeIfAbsent(url, u -> new ConcurrentHashMap<>());
           for (Map.Entry<String, List<URL>> entry : result.entrySet()) {
               String category = entry.getKey();
               List<URL> categoryList = entry.getValue();
               categoryNotified.put(category, categoryList);
               listener.notify(categoryList);
               // 我们将在每次通知后更新缓存文件。
               // 当我们的注册表由于网络抖动而订阅失败时,我们至少可以返回现有的缓存URL。
               saveProperties(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] LiujunjieALiling commented on issue #9212: RegistryService#subscribe为和在服务导出时也要执行?

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


   
   
   
   > 在2.7.8版本中,RegistryService#subscribe到入口为RegistryProtocol#export和RegistryProtocol#doRefer方法,前者为服务导出时调用,后者为服务引用是调用,RegistryProtocol#export方法处理过后的overrideSubscribeUrl格式为:provider://127.0.0.1:20880/com.example.DemoService?category=configurators&check=false&Xxxx=xxxx,当使用nacos作为注册中心时,该调用路径为:RegistryProtocol#export->ListenerRegistryWrapper#subscribe->FailbackRegistry#subscribe->NacosRegistry#doSubscribe->NacosRegistry#notifySubscriber->FailbackRegistry#notify->AbstractRegistry#notify.在这个调用链中,并没有发现有用信息,请问在服务导出时,为啥要调用RegistryService#subscribe方法?
   > 
   > 再看下AbstractRegistry#notify方法:
   > 
   > ```
   > protected void notify(URL url, NotifyListener listener, List<URL> urls) {
   >         if (url == null) {
   >             throw new IllegalArgumentException("notify url == null");
   >         }
   >         if (listener == null) {
   >             throw new IllegalArgumentException("notify listener == null");
   >         }
   >         if ((CollectionUtils.isEmpty(urls))
   >                 && !ANY_VALUE.equals(url.getServiceInterface())) {
   >             logger.warn("Ignore empty notify urls for subscribe url " + url);
   >             return;
   >         }
   >         if (logger.isInfoEnabled()) {
   >             logger.info("Notify urls for subscribe url " + url + ", urls: " + urls);
   >         }
   >         // 保留每个provider的category
   >         Map<String, List<URL>> result = new HashMap<>();
   >         for (URL u : urls) {
   >             if (UrlUtils.isMatch(url, u)) {
   >                 String category = u.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY);
   >                 List<URL> categoryList = result.computeIfAbsent(category, k -> new ArrayList<>());
   >                 categoryList.add(u);
   >             }
   >         }
   >         // 服务导出时的订阅,执行到此就结束了
   >         if (result.size() == 0) {
   >             return;
   >         }
   >         // 添加缓存
   >         Map<String, List<URL>> categoryNotified = notified.computeIfAbsent(url, u -> new ConcurrentHashMap<>());
   >         for (Map.Entry<String, List<URL>> entry : result.entrySet()) {
   >             String category = entry.getKey();
   >             List<URL> categoryList = entry.getValue();
   >             categoryNotified.put(category, categoryList);
   >             listener.notify(categoryList);
   >             // 我们将在每次通知后更新缓存文件。
   >             // 当我们的注册表由于网络抖动而订阅失败时,我们至少可以返回现有的缓存URL。
   >             saveProperties(url);
   >         }
   >     }
   > ```
   
   
           // Deprecated! Subscribe to override rules in 2.6.x or before.
           registry.subscribe(overrideSubscribeUrl, overrideSubscribeListener);   
   


-- 
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