美文网首页Linux学习|Gentoo/Arch/FreeBSD
golang 实现查看遍历zk节点

golang 实现查看遍历zk节点

作者: dwade06 | 来源:发表于2020-04-21 15:13 被阅读0次
    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()
    }
    

    相关文章

      网友评论

        本文标题:golang 实现查看遍历zk节点

        本文链接:https://www.haomeiwen.com/subject/nxguihtx.html