在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
监控代码 package main import ( "go.etcd.io/etcd/clientv3" "time" "fmt" "context" ) func main() { cli, err := clientv3.New(clientv3.Config{ Endpoints:[]string{"localhost:2379", "localhost:23279", "localhost:33279"},//etcd集群三个实例的端口 DialTimeout:2*time.Second, }) if err != nil { fmt.Println("connect failed, err:", err) return } fmt.Println("connect succ") defer cli.Close() for true { rch := cli.Watch(context.Background(), "/logagent/conf/")//阻塞在这里,如果没有key里没有变化,就一直停留在这里 for wresp := range rch{ for _, ev := range wresp.Events{ fmt.Printf("%s %q:%q\n", ev.Type, ev.Kv.Key, ev.Kv.Value) } } } } 配置变更代码 package main import ( "go.etcd.io/etcd/clientv3" "time" "fmt" "context" ) func main() { cli, err := clientv3.New(clientv3.Config{ Endpoints:[]string{"localhost:2379", "localhost:23279", "localhost:33279"}, //etcd的集群的三个实例端口 执行后, 监控代码的执行结果为 |
请发表评论