Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: After disconnection with ZK registry, cosumer can't listen to provider changes #258

Merged
merged 8 commits into from
Dec 4, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions registry/zookeeper/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ func (r *zkRegistry) RestartCallBack() bool {
}
logger.Infof("success to re-register service :%v", confIf.Key())
}
r.listener = zookeeper.NewZkEventListener(r.client)
r.configListener = NewRegistryConfigurationListener(r.client, r)
r.dataListener = NewRegistryDataListener(r.configListener)

return flag
}

Expand Down Expand Up @@ -418,19 +422,24 @@ func (r *zkRegistry) Subscribe(url *common.URL, notifyListener registry.NotifyLi
time.Sleep(time.Duration(RegistryConnDelay) * time.Second)
continue
}

n := 0
for {
n++
if serviceEvent, err := listener.Next(); err != nil {
logger.Warnf("Selector.watch() = error{%v}", perrors.WithStack(err))
listener.Close()
return
if n == 1 {
listener.Close()
pantianying marked this conversation as resolved.
Show resolved Hide resolved
break
}
break
} else {
logger.Infof("update begin, service event: %v", serviceEvent.String())
notifyListener.Notify(serviceEvent)
}

}

logger.Infof("wait for get subscribe listener, key{%v}", url.Key())
sleepWait(n)
}
}

Expand Down Expand Up @@ -485,3 +494,10 @@ func (r *zkRegistry) IsAvailable() bool {
return true
}
}
func sleepWait(n int) {
pantianying marked this conversation as resolved.
Show resolved Hide resolved
wait := time.Duration(200*n) * time.Millisecond
pantianying marked this conversation as resolved.
Show resolved Hide resolved
if wait > 3*time.Second {
pantianying marked this conversation as resolved.
Show resolved Hide resolved
wait = 3 * time.Second
}
time.Sleep(wait)
}