You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by la...@apache.org on 2021/09/01 10:45:43 UTC

[dubbo-go] branch config-enhance updated: fix: support no registry (#1426)

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 ddabb2e  fix: support no registry (#1426)
ddabb2e is described below

commit ddabb2e957aaf19bcf339dcf130a39e9f669ed21
Author: Laurence <45...@users.noreply.github.com>
AuthorDate: Wed Sep 1 18:45:37 2021 +0800

    fix: support no registry (#1426)
---
 config/reference_config.go    |  3 +--
 config/registry_config.go     | 16 ++--------------
 config/root_config.go         |  6 ++++--
 registry/protocol/protocol.go | 41 ++++++++++++++++++++++-------------------
 4 files changed, 29 insertions(+), 37 deletions(-)

diff --git a/config/reference_config.go b/config/reference_config.go
index 2c42e4b..278cbf5 100644
--- a/config/reference_config.go
+++ b/config/reference_config.go
@@ -137,8 +137,7 @@ func (rc *ReferenceConfig) Refer(_ interface{}) {
 	}
 
 	if len(rc.urls) == 1 {
-
-		rc.invoker = extension.GetProtocol("registry").Refer(rc.urls[0])
+		rc.invoker = extension.GetProtocol(rc.urls[0].Protocol).Refer(rc.urls[0])
 		// c.URL != "" is direct call
 		if rc.URL != "" {
 			//filter
diff --git a/config/registry_config.go b/config/registry_config.go
index fe33b17..7759acc 100644
--- a/config/registry_config.go
+++ b/config/registry_config.go
@@ -25,8 +25,6 @@ import (
 
 import (
 	"github.com/creasty/defaults"
-
-	"github.com/pkg/errors"
 )
 
 import (
@@ -73,18 +71,8 @@ func (c *RegistryConfig) check() error {
 	return verify(c)
 }
 
-func initRegistriesConfig(rc *RootConfig) error {
-	registries := rc.Registries
-	if len(registries) <= 0 {
-		return errors.New("dubbo.registries must set")
-	}
-	for _, registry := range registries {
-		if err := registry.check(); err != nil {
-			return err
-		}
-	}
-	rc.Registries = registries
-	return nil
+func (c *RegistryConfig) Init() error {
+	return c.check()
 }
 
 func (c *RegistryConfig) getUrlMap(roleType common.RoleType) url.Values {
diff --git a/config/root_config.go b/config/root_config.go
index d3d49af..0f2337f 100644
--- a/config/root_config.go
+++ b/config/root_config.go
@@ -98,8 +98,10 @@ func (rc *RootConfig) Init() error {
 	if err := initProtocolsConfig(rc); err != nil {
 		return err
 	}
-	if err := initRegistriesConfig(rc); err != nil {
-		return err
+	for i, _ := range rc.Registries {
+		if err := rc.Registries[i].Init(); err != nil {
+			return err
+		}
 	}
 	if err := initLoggerConfig(rc); err != nil {
 		return err
diff --git a/registry/protocol/protocol.go b/registry/protocol/protocol.go
index 8cc1621..37280c7 100644
--- a/registry/protocol/protocol.go
+++ b/registry/protocol/protocol.go
@@ -187,20 +187,21 @@ func (proto *registryProtocol) Export(invoker protocol.Invoker) protocol.Exporte
 	serviceConfigurationListener.OverrideUrl(providerUrl)
 
 	var reg registry.Registry
-	if regI, loaded := proto.registries.Load(registryUrl.Key()); !loaded {
-		reg = getRegistry(registryUrl)
-		proto.registries.Store(registryUrl.Key(), reg)
-		logger.Infof("Export proto:%p registries address:%p", proto, proto.registries)
-	} else {
-		reg = regI.(registry.Registry)
-	}
-
-	registeredProviderUrl := getUrlToRegistry(providerUrl, registryUrl)
-	err := reg.Register(registeredProviderUrl)
-	if err != nil {
-		logger.Errorf("provider service %v register registry %v error, error message is %s",
-			providerUrl.Key(), registryUrl.Key(), err.Error())
-		return nil
+	if registryUrl.Protocol != "" {
+		if regI, loaded := proto.registries.Load(registryUrl.Key()); !loaded {
+			reg = getRegistry(registryUrl)
+			proto.registries.Store(registryUrl.Key(), reg)
+			logger.Infof("Export proto:%p registries address:%p", proto, proto.registries)
+		} else {
+			reg = regI.(registry.Registry)
+		}
+		registeredProviderUrl := getUrlToRegistry(providerUrl, registryUrl)
+		err := reg.Register(registeredProviderUrl)
+		if err != nil {
+			logger.Errorf("provider service %v register registry %v error, error message is %s",
+				providerUrl.Key(), registryUrl.Key(), err.Error())
+			return nil
+		}
 	}
 
 	key := getCacheKey(invoker)
@@ -215,11 +216,13 @@ func (proto *registryProtocol) Export(invoker protocol.Invoker) protocol.Exporte
 		logger.Infof("The exporter has not been cached, and will return a new exporter!")
 	}
 
-	go func() {
-		if err = reg.Subscribe(overriderUrl, overrideSubscribeListener); err != nil {
-			logger.Warnf("reg.subscribe(overriderUrl:%v) = error:%v", overriderUrl, err)
-		}
-	}()
+	if registryUrl.Protocol != "" {
+		go func() {
+			if err := reg.Subscribe(overriderUrl, overrideSubscribeListener); err != nil {
+				logger.Warnf("reg.subscribe(overriderUrl:%v) = error:%v", overriderUrl, err)
+			}
+		}()
+	}
 	return cachedExporter.(protocol.Exporter)
 }