Skip to content
Snippets Groups Projects
Commit dabfdedb authored by renzhiyuan's avatar renzhiyuan Committed by aliiohs
Browse files

add GetBackupUrls method

parent 7b07c345
No related branches found
No related tags found
No related merge requests found
......@@ -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) {
......
......@@ -74,6 +74,7 @@ const (
METHOD_KEYS = "methods"
RULE_KEY = "rule"
RUNTIME_KEY = "runtime"
BACKUP_KEY = "backup"
)
const (
......
......@@ -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 == "" {
......
......@@ -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)
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment