diff --git a/cluster/router_chain.go b/cluster/router_chain.go index 8d7cab21acde92e722317a4b1fd8aa0aa57f1dde..d1b876d0c67a3e260cb5c7a31d50ffba794a3bbc 100644 --- a/cluster/router_chain.go +++ b/cluster/router_chain.go @@ -2,7 +2,6 @@ package cluster import ( "github.com/apache/dubbo-go/common" - "github.com/apache/dubbo-go/common/extension" "github.com/apache/dubbo-go/protocol" "sort" ) @@ -14,21 +13,22 @@ type RouterChain struct { } func NewRouterChain(url common.URL) *RouterChain { - var builtinRouters []Router - factories := extension.GetRouterFactorys() - for _, factory := range factories { - router, _ := factory.Router(&url) - builtinRouters = append(builtinRouters, router) - } - var routers []Router - copy(routers, builtinRouters) - sort.Slice(routers, func(i, j int) bool { - return routers[i].Priority() < routers[j].Priority() - }) - return &RouterChain{ - builtinRouters: routers, - routers: routers, - } + //var builtinRouters []Router + //factories := extension.GetRouterFactories() + //for _, factory := range factories { + // router, _ := factory.Router(&url) + // builtinRouters = append(builtinRouters, router) + //} + //var routers []Router + //copy(routers, builtinRouters) + //sort.Slice(routers, func(i, j int) bool { + // return routers[i].Priority() < routers[j].Priority() + //}) + //return &RouterChain{ + // builtinRouters: routers, + // routers: routers, + //} + return nil } func (r RouterChain) AddRouters(routers []Router) { diff --git a/common/constant/key.go b/common/constant/key.go index af7700af239d8abd3a372fe00fa003977c85c10b..f2e9c222d1c72b34e55fc0ec869869cb1badf1da 100644 --- a/common/constant/key.go +++ b/common/constant/key.go @@ -74,6 +74,7 @@ const ( METHOD_KEYS = "methods" RULE_KEY = "rule" RUNTIME_KEY = "runtime" + BACKUP_KEY = "backup" ) const ( diff --git a/common/url.go b/common/url.go index 2c82082b9750cf854b77272eed08855135a1aa1b..7c38f8869db3739e3ed8a0199e44dae6828e1397 100644 --- a/common/url.go +++ b/common/url.go @@ -242,6 +242,28 @@ func (c URL) Key() string { //return c.ServiceKey() } +//todo +func (c URL) GetBackupUrls() []URL { + var urls []URL + var host string + urls = append(urls, c) + backups := strings.Split(c.GetParam(constant.BACKUP_KEY, ""), "") + for _, address := range backups { + index := strings.LastIndex(address, ":") + port := c.Port + if index > 0 { + host = address[:index] + port = address[index+1:] + } else { + host = string(append([]byte(host), []byte(port)...)) + } + //todo + newURL, _ := NewURL(c.ctx, address) + urls = append(urls, newURL) + } + return urls +} + func (c URL) ServiceKey() string { intf := c.GetParam(constant.INTERFACE_KEY, strings.TrimPrefix(c.Path, "/")) if intf == "" { diff --git a/registry/directory/directory.go b/registry/directory/directory.go index fd4f6bec5fed82ae3dbfe8b003e2ccc220827d0b..b2421d7ec188c9a5da75a9a1bb99b242ac5211b5 100644 --- a/registry/directory/directory.go +++ b/registry/directory/directory.go @@ -19,8 +19,6 @@ package directory import ( "fmt" - "github.com/apache/dubbo-go/common/utils" - "github.com/apache/dubbo-go/version" "reflect" "sync" "time" @@ -37,10 +35,12 @@ import ( "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/common/extension" "github.com/apache/dubbo-go/common/logger" + "github.com/apache/dubbo-go/common/utils" "github.com/apache/dubbo-go/protocol" "github.com/apache/dubbo-go/protocol/protocolwrapper" "github.com/apache/dubbo-go/registry" "github.com/apache/dubbo-go/remoting" + "github.com/apache/dubbo-go/version" ) const ( @@ -131,7 +131,11 @@ func (dir *registryDirectory) update(res *registry.ServiceEvent) { logger.Debugf("registry update, result{%s}", res) logger.Debugf("update service name: %s!", res.Service) + //todo + _ = dir.GetUrl() + if len(dir.Routers()) > 0 { + } dir.refreshInvokers(res) } @@ -228,6 +232,7 @@ func (dir *registryDirectory) List(invocation protocol.Invocation) ([]protocol.I localRouters := dir.Routers() if len(localRouters) > 0 { for _, router := range localRouters { + //todo nil error if reflect.ValueOf(router.Url()).IsNil() || router.Url().GetParamBool(constant.RUNTIME_KEY, false) { invokers = router.Route(invokers, *dir.ConsumerUrl, invocation) }