douzhongjian0752 2018-01-17 10:03
浏览 50

观看不同的客户

I struggle with getting etcd watch working with combination of clients.

What works: I do Watchin golang client and I do put also there. Then watch register change. If I use etcdctl in same way i.e. watch/listen both in command line it also work.

What doesnt work: I publish from command line and watch in go or vice versa.

  • watch commandline, put golang: doesnt work
  • watch commandline, put commandline: works
  • watch golang, put commandline: doesnt work
  • watch golang, put golang: works

By "doesnt work" I mean watcher is not triggered.

Go code I am playing with (you can run like go run main.go (true|false) (true|false)):

package main

import (
    "github.com/coreos/etcd/clientv3"
    "context"
    "time"
    "fmt"
    "os"
)

func main() {
    listen := os.Args[1]
    submit := os.Args[2]
    cfg := clientv3.Config{
        Endpoints: []string{"http://10.0.75.1:2379"},
    }
    c,_ := clientv3.New(cfg)
    if listen == "true" {
        fmt.Println("listening: on")
        ch := c.Watch(context.Background(), "/foo")
        go func() {
            for s := range ch {
                fmt.Println("change: ", string(s.Events[0].Kv.Value))
            }
        }()
    } else {
        fmt.Println("listening: off")
    }
    if submit == "true" {
        fmt.Println("submiting: on")
        go func() {
            for {
                c.Put(context.Background(), "/foo", time.Now().String())
                time.Sleep(1 * time.Second)
            }
        }()
    } else {
        fmt.Println("submiting: off")
    }
    println("waiting 1h")
    time.Sleep(1 * time.Hour)
}

etcdctl commands I am using to publish/watch:

update:

no_proxy=10.0.75.1 ETCDCTL_API=3 etcdctl.exe --endpoints=http://10.0.75.1:2379 put /foo "$(date)"

watch:

no_proxy=10.0.75.1 ETCDCTL_API=3 etcdctl.exe --endpoints=http://10.0.75.1:2379 watch /foo
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度