package main
import (
"fmt"
"github.com/samuel/go-zookeeper/zk"
"time"
)
func ZkStateString(s *zk.Stat) string {
return fmt.Sprintf("Czxid:%d, Mzxid: %d, Ctime: %d, Mtime: %d, Version: %d, Cversion: %d, Aversion: %d, EphemeralOwner: %d, DataLength: %d, NumChildren: %d, Pzxid: %d",
func ZKOperateTest() {
fmt.Printf("ZKOperateTest\n")
var hosts = []string{"127.0.0.1:2181"}
conn, _, err := zk.Connect(hosts, time.Second*5)
if err != nil {
fmt.Println(err)
return
}
defer conn.Close()
var path = "/consumers"
// get
/*_,_,err := conn.Get(path)
if err != nil {
fmt.Println(err)
return
}*/
children, _, err := conn.Children(path)
if err != nil {
return
}
for _, p := range children {
fmt.Println("test node: ", p)
//geti
tmp := path + "/" + p + "/offsets"
fmt.Println("cur node: ", tmp)
child, _, err := conn.Children(tmp)
if err != nil {
continue
}
for _, t := range child {
fmt.Println("test child: ", t);
if t == "topic1" || t == "topic2" {
fmt.Println("wky : ", p)
}
}
}
}
func main() {
ZKOperateTest()
}
有疑问加站长微信联系(非本文作者)