pull/458/head
wangchuxiao 2 years ago
parent db839444f2
commit fca3058db9

@ -44,25 +44,26 @@ func (s *ZkClient) watch() {
func (s *ZkClient) GetConnsRemote(serviceName string) (conns []resolver.Address, err error) { func (s *ZkClient) GetConnsRemote(serviceName string) (conns []resolver.Address, err error) {
path := s.getPath(serviceName) path := s.getPath(serviceName)
_, _, _, err = s.conn.ChildrenW(path)
if err != nil {
return nil, errors.Wrap(err, "children watch error")
}
childNodes, _, err := s.conn.Children(path) childNodes, _, err := s.conn.Children(path)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "get children error") return nil, errors.Wrap(err, "get children error")
} } else {
for _, child := range childNodes { for _, child := range childNodes {
fullPath := path + "/" + child fullPath := path + "/" + child
data, _, err := s.conn.Get(fullPath) data, _, err := s.conn.Get(fullPath)
if err != nil { if err != nil {
if err == zk.ErrNoNode { if err == zk.ErrNoNode {
return nil, errors.Wrap(err, "this is zk ErrNoNode") return nil, errors.Wrap(err, "this is zk ErrNoNode")
}
return nil, errors.Wrap(err, "get children error")
} }
return nil, errors.Wrap(err, "get children error") log.ZDebug(context.Background(), "get conns from remote", "conn", string(data))
conns = append(conns, resolver.Address{Addr: string(data), ServerName: serviceName})
} }
log.ZDebug(context.Background(), "get conns from remote", "conn", string(data))
conns = append(conns, resolver.Address{Addr: string(data), ServerName: serviceName})
}
_, _, _, err = s.conn.ChildrenW(path)
if err != nil {
return nil, errors.Wrap(err, "children watch error")
} }
return conns, nil return conns, nil
} }

@ -8,6 +8,15 @@ import (
"google.golang.org/grpc/resolver" "google.golang.org/grpc/resolver"
) )
func (s *ZkClient) CreateRpcRootNodes(serviceNames []string) error {
for _, serviceName := range serviceNames {
if err := s.ensureName(serviceName); err != nil {
return err
}
}
return nil
}
func (s *ZkClient) Register(rpcRegisterName, host string, port int, opts ...grpc.DialOption) error { func (s *ZkClient) Register(rpcRegisterName, host string, port int, opts ...grpc.DialOption) error {
if err := s.ensureName(rpcRegisterName); err != nil { if err := s.ensureName(rpcRegisterName); err != nil {
return err return err

Loading…
Cancel
Save