You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "mark4z (via GitHub)" <gi...@apache.org> on 2023/02/23 09:15:01 UTC
[GitHub] [dubbo-go] mark4z commented on a diff in pull request #2205: add serviceMappingListener for application service discovery
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-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