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/05 05:15:16 UTC

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

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


##########
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 吗?你的把事件塞到 chan 里面去呀,不然你下面的 listener.Next 等啥呢?



##########
registry/polaris/registry.go:
##########
@@ -67,11 +68,13 @@ func newPolarisRegistry(url *common.URL) (registry.Registry, error) {
 }
 
 type polarisRegistry struct {
+	consumer     api.ConsumerAPI
+	namespace    string

Review Comment:
   这个 ns 信息在哪里初始化呢?



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