Skip to content
Snippets Groups Projects
Commit 8a17274d authored by 邹毅贤's avatar 邹毅贤
Browse files

fix file config init invliad

parent ec066c38
No related branches found
No related tags found
No related merge requests found
......@@ -31,8 +31,11 @@ import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/dubbogo/gost/container/set"
)
var routerURLSet = gxset.NewSet()
// BaseDirectory ...
type BaseDirectory struct {
url *common.URL
......@@ -102,3 +105,7 @@ func (dir *BaseDirectory) Destroy(doDestroy func()) {
func (dir *BaseDirectory) IsAvailable() bool {
return !dir.destroyed.Load()
}
func GetRouterURLSet() *gxset.HashSet {
return routerURLSet
}
......@@ -55,7 +55,7 @@ func (l *listenableRouter) RouterRule() *RouterRule {
func newListenableRouter(url *common.URL, ruleKey string) (*AppRouter, error) {
if ruleKey == "" {
return nil, perrors.Errorf("newListenableRouter ruleKey is nil, can't create Listenable router")
return nil, perrors.Errorf("NewListenableRouter ruleKey is nil, can't create Listenable router")
}
l := &AppRouter{}
......@@ -66,20 +66,21 @@ func newListenableRouter(url *common.URL, ruleKey string) (*AppRouter, error) {
//add listener
dynamicConfiguration := config.GetEnvInstance().GetDynamicConfiguration()
if dynamicConfiguration == nil {
return nil, perrors.Errorf("get dynamicConfiguration fail, dynamicConfiguration is nil, init config center plugin please")
return nil, perrors.Errorf("Get dynamicConfiguration fail, dynamicConfiguration is nil, init config center plugin please")
}
dynamicConfiguration.AddListener(routerKey, l)
//get rule
rule, err := dynamicConfiguration.GetRule(routerKey, config_center.WithGroup(config_center.DEFAULT_GROUP))
if len(rule) == 0 || err != nil {
return nil, perrors.Errorf("get rule fail, config rule{%s}, error{%v}", rule, err)
return nil, perrors.Errorf("Get rule fail, config rule{%s}, error{%v}", rule, err)
}
l.Process(&config_center.ConfigChangeEvent{
Key: routerKey,
Value: rule,
ConfigType: remoting.EventTypeUpdate})
logger.Info("Init app router success")
return l, nil
}
......
......@@ -58,6 +58,7 @@ func RouterInit(confRouterFile string) error {
}
logger.Debugf("router config{%#v}\n", routerConfig)
directory.GetRouterURLSet().Add(initRouterUrl())
return nil
}
......
......@@ -134,6 +134,10 @@ func (dir *registryDirectory) refreshInvokers(res *registry.ServiceEvent) {
dirUrl := &res.Service
var urls []*common.URL
for _, v := range directory.GetRouterURLSet().Values() {
urls = append(urls, v.(*common.URL))
}
for _, v := range dirUrl.GetBackupUrls() {
p := v.Protocol
category := v.GetParam(constant.CATEGORY_KEY, constant.PROVIDERS_CATEGORY)
......@@ -144,6 +148,7 @@ func (dir *registryDirectory) refreshInvokers(res *registry.ServiceEvent) {
if len(urls) > 0 {
routers := toRouters(urls)
logger.Infof("Init file condition router success, size: %v", len(routers))
if len(routers) > 0 {
dir.SetRouters(routers)
}
......
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