mark4z commented on code in PR #2205: URL: https://github.com/apache/dubbo-go/pull/2205#discussion_r1115405932
########## metadata/report/nacos/report.go: ########## @@ -209,6 +210,34 @@ func (n *nacosMetadataReport) getConfig(param vo.ConfigParam) (string, error) { return cfg, nil } +func (n *nacosMetadataReport) addListener(key string, group string, notify registry.MappingListener) error { + return n.client.Client().ListenConfig(vo.ConfigParam{ + DataId: key, + Group: group, + OnChange: func(namespace, group, dataId, data string) { + go callback(notify, dataId, data) + }, + }) +} + +func callback(notify registry.MappingListener, dataId, data string) { + appNames := strings.Split(data, constant.CommaSeparator) + set := gxset.NewSet() + for _, app := range appNames { + set.Add(app) + } + if err := notify.OnEvent(registry.NewServiceMappingChangedEvent(dataId, set)); err != nil { + logger.Errorf("serviceMapping callback err: %s", err.Error()) + } +} + +func (n *nacosMetadataReport) removeServiceMappingListener(key string, group string) error { + return n.client.Client().CancelListenConfig(vo.ConfigParam{ + DataId: key, + Group: group, + }) +} + // RegisterServiceAppMapping map the specified Dubbo service interface to current Dubbo app name func (n *nacosMetadataReport) RegisterServiceAppMapping(key string, group string, value string) error { oldVal, err := n.getConfig(vo.ConfigParam{ Review Comment: OldVal is a list of service names. If strings.Contains(oldVal, newServiceName), then the SNP registration will be skipped, e.g. if oldVal = dubbo.io-2 and newServiceName = dubbo.io, then newServiceName will be skipped. -- 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-unsubscr...@dubbo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org For additional commands, e-mail: notifications-h...@dubbo.apache.org