Skip to content

Commit

Permalink
Merge pull request #359 from hxmhlt/mod_zk_listen
Browse files Browse the repository at this point in the history
Mod:cancel listener dir when zkpath end of providers/ & consumers/
  • Loading branch information
pantianying authored Feb 19, 2020
2 parents 26238d4 + e501e80 commit 2d4022d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions common/constant/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const (
DYNAMIC_CONFIGURATORS_CATEGORY = "dynamicconfigurators"
APP_DYNAMIC_CONFIGURATORS_CATEGORY = "appdynamicconfigurators"
PROVIDER_CATEGORY = "providers"
CONSUMER_CATEGORY = "consumers"
)

const (
Expand Down
14 changes: 10 additions & 4 deletions remoting/zookeeper/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package zookeeper

import (
"path"
"strings"
"sync"
"time"
)
Expand All @@ -30,6 +31,7 @@ import (
)

import (
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/remoting"
)
Expand Down Expand Up @@ -256,10 +258,14 @@ func (l *ZkEventListener) listenDirEvent(zkPath string, listener remoting.DataLi
}(dubboPath, listener)

//listen sub path recursive
go func(zkPath string, listener remoting.DataListener) {
l.listenDirEvent(zkPath, listener)
logger.Warnf("listenDirEvent(zkPath{%s}) goroutine exit now", zkPath)
}(dubboPath, listener)
//if zkPath is end of "providers/ & consumers/" we do not listen children dir
if strings.LastIndex(zkPath, constant.PROVIDER_CATEGORY) == -1 &&
strings.LastIndex(zkPath, constant.CONSUMER_CATEGORY) == -1 {
go func(zkPath string, listener remoting.DataListener) {
l.listenDirEvent(zkPath, listener)
logger.Warnf("listenDirEvent(zkPath{%s}) goroutine exit now", zkPath)
}(dubboPath, listener)
}
}
select {
case zkEvent = <-childEventCh:
Expand Down

0 comments on commit 2d4022d

Please sign in to comment.