This is an automated email from the ASF dual-hosted git repository. albumenj pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/main by this push: new bf1a00ab2 fix service discovery issue with nacos (#2694) bf1a00ab2 is described below commit bf1a00ab21bd68bf9ff7ed1c6dac27acd71323b7 Author: Ken Liu <ken.lj...@gmail.com> AuthorDate: Thu Jul 4 09:45:19 2024 +0800 fix service discovery issue with nacos (#2694) --- registry/nacos/service_discovery.go | 2 +- .../servicediscovery/service_discovery_registry.go | 11 ++++++----- .../service_instances_changed_listener_impl.go | 23 +++++++++++----------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/registry/nacos/service_discovery.go b/registry/nacos/service_discovery.go index 7f2f2cae3..7fa41b621 100644 --- a/registry/nacos/service_discovery.go +++ b/registry/nacos/service_discovery.go @@ -261,7 +261,7 @@ func (n *nacosServiceDiscovery) AddListener(listener registry.ServiceInstancesCh instances = append(instances, ®istry.DefaultServiceInstance{ ID: id, - ServiceName: service.ServiceName, + ServiceName: serviceName, Host: service.Ip, Port: int(service.Port), Enable: service.Enable, diff --git a/registry/servicediscovery/service_discovery_registry.go b/registry/servicediscovery/service_discovery_registry.go index 70075db91..f2ad8fadf 100644 --- a/registry/servicediscovery/service_discovery_registry.go +++ b/registry/servicediscovery/service_discovery_registry.go @@ -210,18 +210,19 @@ func (s *ServiceDiscoveryRegistry) Subscribe(url *common.URL, notify registry.No } _, err := s.metaDataService.SubscribeURL(url) if err != nil { - return perrors.WithMessage(err, "subscribe url error: "+url.String()) + return perrors.WithMessage(err, "save subscribe url error: "+url.String()) } mappingListener := NewMappingListener(s.url, url, s.subscribedServices, notify) services := s.getServices(url, mappingListener) if services.Empty() { - return perrors.Errorf("Should has at least one way to know which services this interface belongs to,"+ + logger.Infof("Should has at least one way to know which services this interface belongs to,"+ " either specify 'provided-by' for reference or enable metadata-report center subscription url:%s", url.String()) + } else { + logger.Infof("Find initial mapping applications %q for service %s.", services, url.ServiceKey()) + // first notify + err = mappingListener.OnEvent(registry.NewServiceMappingChangedEvent(url.ServiceKey(), services)) } - logger.Infof("Find initial mapping applications %q for service %s.", services, url.ServiceKey()) - // first notify - err = mappingListener.OnEvent(registry.NewServiceMappingChangedEvent(url.ServiceKey(), services)) if err != nil { logger.Errorf("[ServiceDiscoveryRegistry] ServiceInstancesChangedListenerImpl handle error:%v", err) } diff --git a/registry/servicediscovery/service_instances_changed_listener_impl.go b/registry/servicediscovery/service_instances_changed_listener_impl.go index 8799cb055..e0e7d2189 100644 --- a/registry/servicediscovery/service_instances_changed_listener_impl.go +++ b/registry/servicediscovery/service_instances_changed_listener_impl.go @@ -159,20 +159,21 @@ func (lstn *ServiceInstancesChangedListenerImpl) OnEvent(e observer.Event) error newServiceURLs[serviceInfo.GetMatchKey()] = urls } } - lstn.serviceUrls = newServiceURLs + } - for key, notifyListener := range lstn.listeners { - urls := lstn.serviceUrls[key] - events := make([]*registry.ServiceEvent, 0, len(urls)) - for _, url := range urls { - events = append(events, ®istry.ServiceEvent{ - Action: remoting.EventTypeAdd, - Service: url, - }) - } - notifyListener.NotifyAll(events, func() {}) + lstn.serviceUrls = newServiceURLs + for key, notifyListener := range lstn.listeners { + urls := lstn.serviceUrls[key] + events := make([]*registry.ServiceEvent, 0, len(urls)) + for _, url := range urls { + events = append(events, ®istry.ServiceEvent{ + Action: remoting.EventTypeAdd, + Service: url, + }) } + notifyListener.NotifyAll(events, func() {}) } + return nil }