This is an automated email from the ASF dual-hosted git repository.

laurence pushed a commit to branch config-enhance
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/config-enhance by this push:
     new 526ea1a  Feat: config enhance (service discovery) (#1469)
526ea1a is described below

commit 526ea1a8a28c8aca065803cef3a0e2e4e07c1ff7
Author: MasterKenway <[email protected]>
AuthorDate: Fri Sep 24 13:33:29 2021 +0800

    Feat: config enhance (service discovery) (#1469)
    
    * feat: fit metadata report config
    
    * feat: add export after config load
    style: remove redundant imports
    fix: remove nacos redundant n.group
    
    * fix: remove useless code
---
 config/config_loader.go              |  7 +++++++
 registry/etcdv3/service_discovery.go | 31 +++++++++----------------------
 registry/file/service_discovery.go   |  4 +---
 registry/nacos/service_discovery.go  |  2 +-
 4 files changed, 18 insertions(+), 26 deletions(-)

diff --git a/config/config_loader.go b/config/config_loader.go
index c8e529b..e15cb7e 100644
--- a/config/config_loader.go
+++ b/config/config_loader.go
@@ -382,6 +382,13 @@ func registerServiceInstance() {
                        
remoteMetadataService.PublishMetadata(GetApplicationConfig().Name)
                }
        }
+
+       if GetApplicationConfig().MetadataType == 
constant.REMOTE_METADATA_STORAGE_TYPE {
+               // publish metadata to remote
+               if remoteMetadataService, err := 
extension.GetRemoteMetadataService(); err == nil {
+                       
remoteMetadataService.PublishMetadata(GetApplicationConfig().Name)
+               }
+       }
 }
 
 //
diff --git a/registry/etcdv3/service_discovery.go 
b/registry/etcdv3/service_discovery.go
index a467633..214ea42 100644
--- a/registry/etcdv3/service_discovery.go
+++ b/registry/etcdv3/service_discovery.go
@@ -30,8 +30,6 @@ import (
        gxpage "github.com/dubbogo/gost/hash/page"
 
        "github.com/hashicorp/vault/sdk/helper/jsonutil"
-
-       perrors "github.com/pkg/errors"
 )
 
 import (
@@ -292,38 +290,27 @@ func (e *etcdV3ServiceDiscovery) DataChange(eventType 
remoting.Event) bool {
        return true
 }
 
-// netEcdv3ServiceDiscovery
+// newEtcdv3ServiceDiscovery
 func newEtcdV3ServiceDiscovery() (registry.ServiceDiscovery, error) {
        initLock.Lock()
        defer initLock.Unlock()
 
-       // todo fix
-       sdc, ok := config.GetRootConfig().ServiceDiscoveries[""]
-       if !ok || len(sdc.RemoteRef) == 0 {
-               return nil, perrors.New("could not init the etcd service 
instance because the config is invalid")
-       }
+       metadataReportConfig := config.GetMetadataReportConfg()
 
-       remoteConfig, ok := config.GetRootConfig().Remotes[sdc.RemoteRef]
-       if !ok {
-               return nil, perrors.New("could not find the remote config for 
name: " + sdc.RemoteRef)
-       }
-
-       // init etcdv3 client
-       timeout, err := time.ParseDuration(remoteConfig.TimeoutStr)
+       to, err := time.ParseDuration(metadataReportConfig.Timeout)
        if err != nil {
-               logger.Errorf("timeout config %v is invalid,err is %v", 
remoteConfig.TimeoutStr, err.Error())
-               return nil, perrors.WithMessagef(err, "new etcd service 
discovery(address:%v)", remoteConfig.Address)
+               logger.Errorf("timeout config %v is invalid,err is %v", 
metadataReportConfig.Timeout, err.Error())
+               return nil, err
        }
-
-       logger.Infof("etcd address is: %v,timeout is:%s", remoteConfig.Address, 
timeout.String())
+       logger.Infof("etcd address is: %v,timeout is:%s", 
metadataReportConfig.Timeout, to.String())
 
        client := etcdv3.NewServiceDiscoveryClient(
                gxetcd.WithName(gxetcd.RegistryETCDV3Client),
-               gxetcd.WithTimeout(timeout),
-               gxetcd.WithEndpoints(strings.Split(remoteConfig.Address, 
",")...),
+               gxetcd.WithTimeout(to),
+               
gxetcd.WithEndpoints(strings.Split(metadataReportConfig.Address, ",")...),
        )
 
-       descriptor := fmt.Sprintf("etcd-service-discovery[%s]", 
remoteConfig.Address)
+       descriptor := fmt.Sprintf("etcd-service-discovery[%s]", 
metadataReportConfig.Address)
 
        return &etcdV3ServiceDiscovery{descriptor, client, nil, gxset.NewSet(), 
make(map[string]*etcdv3.EventListener)}, nil
 }
diff --git a/registry/file/service_discovery.go 
b/registry/file/service_discovery.go
index e8657d9..1c74163 100644
--- a/registry/file/service_discovery.go
+++ b/registry/file/service_discovery.go
@@ -57,9 +57,7 @@ type fileSystemServiceDiscovery struct {
 }
 
 func newFileSystemServiceDiscovery() (registry.ServiceDiscovery, error) {
-       // todo fix
-       sdc, ok := config.GetRootConfig().ServiceDiscoveries[""]
-       if !ok || sdc.Protocol != constant.FILE_KEY {
+       if config.GetMetadataReportConfg().Protocol != constant.FILE_KEY {
                return nil, perrors.New("could not init the instance because 
the config is invalid")
        }
 
diff --git a/registry/nacos/service_discovery.go 
b/registry/nacos/service_discovery.go
index b744dc8..ee7e276 100644
--- a/registry/nacos/service_discovery.go
+++ b/registry/nacos/service_discovery.go
@@ -218,8 +218,8 @@ func (n *nacosServiceDiscovery) AddListener(listener 
registry.ServiceInstancesCh
        for _, t := range listener.GetServiceNames().Values() {
                serviceName := t.(string)
                err := n.namingClient.Client().Subscribe(&vo.SubscribeParam{
-                       ServiceName: serviceName,
                        GroupName:   n.group,
+                       ServiceName: serviceName,
                        SubscribeCallback: func(services 
[]model.SubscribeService, err error) {
                                if err != nil {
                                        logger.Errorf("Could not handle the 
subscribe notification because the err is not nil."+

Reply via email to