You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2026/03/06 21:33:10 UTC

(dubbo-go) branch develop updated: fix(router): call BuildRouterChain method when creating directory. (#3225)

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

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


The following commit(s) were added to refs/heads/develop by this push:
     new 9d591336c fix(router): call BuildRouterChain method when creating directory. (#3225)
9d591336c is described below

commit 9d591336c0fea3a60cf9c12836e1bfef60e85a9b
Author: yangpixi <63...@users.noreply.github.com>
AuthorDate: Sat Mar 7 05:33:04 2026 +0800

    fix(router): call BuildRouterChain method when creating directory. (#3225)
    
    * fix(router): call BuildRouterChain method when creating static directory.
    
    * style: use imports-formatter to format code
    
    * ci: register router factory method in unit test.
    
    * ci: import tag router package to resolve no router factory problem.
    
    * fix: add failback, remove unnecessary import
    
    * fix: refactor failback mechanic, return the exception that len(URLs) equals 0
---
 client/action.go                                  | 7 +++++++
 cluster/cluster/available/cluster_invoker_test.go | 1 +
 cluster/cluster/broadcast/cluster_invoker_test.go | 1 +
 cluster/cluster/failback/cluster_test.go          | 1 +
 cluster/cluster/failfast/cluster_test.go          | 1 +
 cluster/cluster/failover/cluster_test.go          | 1 +
 cluster/cluster/failsafe/cluster_test.go          | 1 +
 cluster/cluster/forking/cluster_test.go           | 1 +
 cluster/cluster/zoneaware/cluster_invoker_test.go | 1 +
 cluster/directory/static/directory.go             | 9 ++++++++-
 cluster/directory/static/directory_test.go        | 1 +
 11 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/client/action.go b/client/action.go
index fd6a3b4d2..75e95a6c1 100644
--- a/client/action.go
+++ b/client/action.go
@@ -30,6 +30,8 @@ import (
 	gxstrings "github.com/dubbogo/gost/strings"
 
 	constant2 "github.com/dubbogo/triple/pkg/common/constant"
+
+	perrors "github.com/pkg/errors"
 )
 
 import (
@@ -256,6 +258,11 @@ func buildInvoker(urls []*common.URL, ref *global.ReferenceConfig) (base.Invoker
 		invoker base.Invoker
 		regURL  *common.URL
 	)
+
+	if len(urls) == 0 {
+		return nil, perrors.New("invoker list is empty")
+	}
+
 	invokers := make([]base.Invoker, len(urls))
 	for i, u := range urls {
 		if u.Protocol == constant.ServiceRegistryProtocol {
diff --git a/cluster/cluster/available/cluster_invoker_test.go b/cluster/cluster/available/cluster_invoker_test.go
index 8522c53ab..efcc17faa 100644
--- a/cluster/cluster/available/cluster_invoker_test.go
+++ b/cluster/cluster/available/cluster_invoker_test.go
@@ -35,6 +35,7 @@ import (
 	clusterpkg "dubbo.apache.org/dubbo-go/v3/cluster/cluster"
 	"dubbo.apache.org/dubbo-go/v3/cluster/directory/static"
 	"dubbo.apache.org/dubbo-go/v3/cluster/loadbalance/random"
+	_ "dubbo.apache.org/dubbo-go/v3/cluster/router/tag"
 	"dubbo.apache.org/dubbo-go/v3/common"
 	"dubbo.apache.org/dubbo-go/v3/common/constant"
 	"dubbo.apache.org/dubbo-go/v3/common/extension"
diff --git a/cluster/cluster/broadcast/cluster_invoker_test.go b/cluster/cluster/broadcast/cluster_invoker_test.go
index 0e829715c..d6c808ddc 100644
--- a/cluster/cluster/broadcast/cluster_invoker_test.go
+++ b/cluster/cluster/broadcast/cluster_invoker_test.go
@@ -34,6 +34,7 @@ import (
 	clusterpkg "dubbo.apache.org/dubbo-go/v3/cluster/cluster"
 	"dubbo.apache.org/dubbo-go/v3/cluster/directory/static"
 	"dubbo.apache.org/dubbo-go/v3/cluster/loadbalance/random"
+	_ "dubbo.apache.org/dubbo-go/v3/cluster/router/tag"
 	"dubbo.apache.org/dubbo-go/v3/common"
 	"dubbo.apache.org/dubbo-go/v3/common/constant"
 	"dubbo.apache.org/dubbo-go/v3/common/extension"
diff --git a/cluster/cluster/failback/cluster_test.go b/cluster/cluster/failback/cluster_test.go
index 89f9ae58e..34eb5366b 100644
--- a/cluster/cluster/failback/cluster_test.go
+++ b/cluster/cluster/failback/cluster_test.go
@@ -39,6 +39,7 @@ import (
 	clusterpkg "dubbo.apache.org/dubbo-go/v3/cluster/cluster"
 	"dubbo.apache.org/dubbo-go/v3/cluster/directory/static"
 	"dubbo.apache.org/dubbo-go/v3/cluster/loadbalance/random"
+	_ "dubbo.apache.org/dubbo-go/v3/cluster/router/tag"
 	"dubbo.apache.org/dubbo-go/v3/common"
 	"dubbo.apache.org/dubbo-go/v3/common/constant"
 	"dubbo.apache.org/dubbo-go/v3/common/extension"
diff --git a/cluster/cluster/failfast/cluster_test.go b/cluster/cluster/failfast/cluster_test.go
index 40126bcd6..6e1fc7976 100644
--- a/cluster/cluster/failfast/cluster_test.go
+++ b/cluster/cluster/failfast/cluster_test.go
@@ -36,6 +36,7 @@ import (
 	clusterpkg "dubbo.apache.org/dubbo-go/v3/cluster/cluster"
 	"dubbo.apache.org/dubbo-go/v3/cluster/directory/static"
 	"dubbo.apache.org/dubbo-go/v3/cluster/loadbalance/random"
+	_ "dubbo.apache.org/dubbo-go/v3/cluster/router/tag"
 	"dubbo.apache.org/dubbo-go/v3/common"
 	"dubbo.apache.org/dubbo-go/v3/common/constant"
 	"dubbo.apache.org/dubbo-go/v3/common/extension"
diff --git a/cluster/cluster/failover/cluster_test.go b/cluster/cluster/failover/cluster_test.go
index 346dfee68..a1dbe28f2 100644
--- a/cluster/cluster/failover/cluster_test.go
+++ b/cluster/cluster/failover/cluster_test.go
@@ -33,6 +33,7 @@ import (
 	clusterpkg "dubbo.apache.org/dubbo-go/v3/cluster/cluster"
 	"dubbo.apache.org/dubbo-go/v3/cluster/directory/static"
 	"dubbo.apache.org/dubbo-go/v3/cluster/loadbalance/random"
+	_ "dubbo.apache.org/dubbo-go/v3/cluster/router/tag"
 	"dubbo.apache.org/dubbo-go/v3/common"
 	"dubbo.apache.org/dubbo-go/v3/common/constant"
 	"dubbo.apache.org/dubbo-go/v3/common/extension"
diff --git a/cluster/cluster/failsafe/cluster_test.go b/cluster/cluster/failsafe/cluster_test.go
index 44d224135..f8268bdc2 100644
--- a/cluster/cluster/failsafe/cluster_test.go
+++ b/cluster/cluster/failsafe/cluster_test.go
@@ -36,6 +36,7 @@ import (
 	clusterpkg "dubbo.apache.org/dubbo-go/v3/cluster/cluster"
 	"dubbo.apache.org/dubbo-go/v3/cluster/directory/static"
 	"dubbo.apache.org/dubbo-go/v3/cluster/loadbalance/random"
+	_ "dubbo.apache.org/dubbo-go/v3/cluster/router/tag"
 	"dubbo.apache.org/dubbo-go/v3/common"
 	"dubbo.apache.org/dubbo-go/v3/common/constant"
 	"dubbo.apache.org/dubbo-go/v3/common/extension"
diff --git a/cluster/cluster/forking/cluster_test.go b/cluster/cluster/forking/cluster_test.go
index 627dad504..3eec6dce0 100644
--- a/cluster/cluster/forking/cluster_test.go
+++ b/cluster/cluster/forking/cluster_test.go
@@ -37,6 +37,7 @@ import (
 	clusterpkg "dubbo.apache.org/dubbo-go/v3/cluster/cluster"
 	"dubbo.apache.org/dubbo-go/v3/cluster/directory/static"
 	"dubbo.apache.org/dubbo-go/v3/cluster/loadbalance/roundrobin"
+	_ "dubbo.apache.org/dubbo-go/v3/cluster/router/tag"
 	"dubbo.apache.org/dubbo-go/v3/common"
 	"dubbo.apache.org/dubbo-go/v3/common/constant"
 	"dubbo.apache.org/dubbo-go/v3/common/extension"
diff --git a/cluster/cluster/zoneaware/cluster_invoker_test.go b/cluster/cluster/zoneaware/cluster_invoker_test.go
index 037f9d3c7..7d657d028 100644
--- a/cluster/cluster/zoneaware/cluster_invoker_test.go
+++ b/cluster/cluster/zoneaware/cluster_invoker_test.go
@@ -34,6 +34,7 @@ import (
 	clusterpkg "dubbo.apache.org/dubbo-go/v3/cluster/cluster"
 	"dubbo.apache.org/dubbo-go/v3/cluster/directory/static"
 	"dubbo.apache.org/dubbo-go/v3/cluster/loadbalance/random"
+	_ "dubbo.apache.org/dubbo-go/v3/cluster/router/tag"
 	"dubbo.apache.org/dubbo-go/v3/common"
 	"dubbo.apache.org/dubbo-go/v3/common/constant"
 	"dubbo.apache.org/dubbo-go/v3/common/extension"
diff --git a/cluster/directory/static/directory.go b/cluster/directory/static/directory.go
index d0f96a823..f2a9a4603 100644
--- a/cluster/directory/static/directory.go
+++ b/cluster/directory/static/directory.go
@@ -18,6 +18,8 @@
 package static
 
 import (
+	"github.com/dubbogo/gost/log/logger"
+
 	perrors "github.com/pkg/errors"
 )
 
@@ -45,7 +47,12 @@ func NewDirectory(invokers []protocolbase.Invoker) *directory {
 		invokers:  invokers,
 	}
 
-	dir.RouterChain().SetInvokers(invokers)
+	err := dir.BuildRouterChain(invokers, url)
+	if err != nil {
+		logger.Error(err)
+		dir.RouterChain().SetInvokers(invokers)
+	}
+
 	return dir
 }
 
diff --git a/cluster/directory/static/directory_test.go b/cluster/directory/static/directory_test.go
index 8098cf5e3..78ab16794 100644
--- a/cluster/directory/static/directory_test.go
+++ b/cluster/directory/static/directory_test.go
@@ -27,6 +27,7 @@ import (
 )
 
 import (
+	_ "dubbo.apache.org/dubbo-go/v3/cluster/router/tag"
 	"dubbo.apache.org/dubbo-go/v3/common"
 	"dubbo.apache.org/dubbo-go/v3/protocol/base"
 	"dubbo.apache.org/dubbo-go/v3/protocol/invocation"