huwenming-saw commented on issue #10393:
URL: https://github.com/apache/dubbo/issues/10393#issuecomment-1272713597

   > 那么当 nacos通知A2无实例时,调用nacosListener,监听器中调用notifySubscriber(url, serviceName, 
listener, instances);
   但是这个serviceNames是A1,变成了通知A1无实例
   
   @404008945  
是的,我也认为是这样的,共用同一个EventListener,但是因为匿名内部类的原因导致调用notifySubscriber(url, 
serviceName, listener, instances)时的serviceName相同。@AlbumenJ  
虽然NacosAggregateListener内部会聚合,但是因为公用同一个EventListener的serviceName相同都是A1,导致NacosAggregateListener聚合时出现全部为空的A1无实例
   ```java
       private void notifySubscriber(URL url, String serviceName, 
NacosAggregateListener listener, Collection<Instance> instances) {
           List<Instance> enabledInstances = new LinkedList<>(instances);
           if (enabledInstances.size() > 0) {
               //  Instances
               filterEnabledInstances(enabledInstances);
           }
           //saveAndAggregateAllInstances方法被触发,返回的是多个serviceName的聚合结果
           List<URL> aggregatedUrls = toUrlWithEmpty(url, 
listener.saveAndAggregateAllInstances(serviceName, enabledInstances));
           NacosRegistry.this.notify(url, listener.getNotifyListener(), 
aggregatedUrls);
       }
   
       public List<Instance> saveAndAggregateAllInstances(String serviceName, 
List<Instance> instances) {
           serviceNames.add(serviceName);
           serviceInstances.put(serviceName, 
instances);//serviceInstances本来是{A1:instances,A2:emptyinstances},因为EventListener的serviceName相同都是A1,Nacos根据订阅通知时导致serviceInstances里边全部被替换为{A1:emptyinstances,A2:emptyinstances}
           return 
serviceInstances.values().stream().flatMap(List::stream).collect(Collectors.toList());
       }
   ```
   
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to