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 2022/11/08 03:27:09 UTC

[GitHub] [dubbo-go] jasondeng1997 commented on a diff in pull request #2100: add polaris subscribe

jasondeng1997 commented on code in PR #2100:
URL: https://github.com/apache/dubbo-go/pull/2100#discussion_r1016108005


##########
registry/polaris/registry.go:
##########
@@ -159,21 +158,43 @@ func (pr *polarisRegistry) Subscribe(url *common.URL, notifyListener registry.No
 
 	for {
 		listener, err := NewPolarisListener(url)
+
 		if err != nil {
 			logger.Warnf("getListener() = err:%v", perrors.WithStack(err))
 			<-time.After(time.Duration(RegistryConnDelay) * time.Second)
 			continue
 		}
+		serviceName := getServiceName(url)
+		watcher, err := pr.createPolarisWatcher(serviceName)
+		if err != nil {
+			return err
+		}
 
-		watcher, err := newPolarisWatcher(&newParam, newConsumer)
+		watcher.AddSubscriber(func(et remoting.EventType, instances []model.Instance) {
+			dubboInstances := make([]registry.ServiceInstance, 0, len(instances))
+			for _, instance := range instances {
+				dubboInstances = append(dubboInstances, &registry.DefaultServiceInstance{
+					ID:          instance.GetId(),
+					ServiceName: instance.GetService(),
+					Host:        instance.GetHost(),
+					Port:        int(instance.GetPort()),
+					Enable:      !instance.IsIsolated(),
+					Healthy:     instance.IsHealthy(),
+					Metadata:    instance.GetMetadata(),
+					GroupName:   instance.GetMetadata()[constant.PolarisDubboGroup],
+				})
+			}
+			registry.NewServiceInstancesChangedEvent(serviceName, dubboInstances)
+			listener.Next()

Review Comment:
   这个事件需要传递给listener吗,这个是一个notify事件,执行通知就行了



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