当我使用etcd客户端go.etcd.io/etcd/clientv3
观看etcd事件时,我发现我将收到许多带有空事件的响应。登录以下:
ime =“ 2019-10-27T20:39:13 + 08:00” level = debug msg =“ ETCD监视响应:{Header:{ClusterId:0 MemberId:0 Revision:0 RaftTerm:0}事件:[]CompactRevision:0取消:false创建:false closeErr:cancelReason:}“ file =” backend.go:135“ time =” 2019-10-27T20:39:13 + 08:00“level = debug msg =“ ETCD监视响应:{Header:{ClusterId:0 MemberId:0修订:0 RaftTerm:0}事件:[] CompactRevision:0已取消:false创建:false closeErr:cancelReason:}“ file =” backend.go:135“time =“ 2019-10-27T20:39:13 + 08:00” level = debug msg =“ ETCD观看响应:{Header:{ClusterId:0 MemberId:0 Revision:0 RaftTerm:0}事件:[]CompactRevision:0取消:false创建:false closeErr:cancelReason:}“ file =” backend.go:135“ time =” 2019-10-27T20:39:13 + 08:00“level = debug msg =“ ETCD监视响应:{Header:{ClusterId:0 MemberId:0修订:0 RaftTerm:0}事件:[] CompactRevision:0已取消:false创建:false closeErr:cancelReason:}“ file =” backend.go:135“time =“ 2019-10-27T20:39:13 + 08:00” level = debug msg =“ ETCD观看响应:{Header:{ClusterId:0 MemberId:0 Revision:0 RaftTerm:0}事件:[]CompactRevision:0取消:false创建:false closeErr:cancelReason:}“ file =” backend.go:135“ time =” 2019-10-27T20:39:13 + 08:00“level = debug msg =“ ETCD监视响应:{Header:{ClusterId:0 MemberId:0修订:0 RaftTerm:0}事件:[] CompactRevision:0已取消:false创建:false closeErr:cancelReason:}“ file =” backend.go:135“time =“ 2019-10-27T20:39:13 + 08:00” level = debug msg =“ ETCD观看响应:{Header:{ClusterId:0 MemberId:0 Revision:0 RaftTerm:0}事件:[]CompactRevision:0取消:false创建:false closeErr:cancelReason:}“ file =” backend.go:135“ time =” 2019-10-27T20:39:13 + 08:00“level = debug msg =“ ETCD监视响应:{Header:{ClusterId:0 MemberId:0修订:0 RaftTerm:0}事件:[] CompactRevision:0已取消:false创建:false closeErr:cancelReason:}“ file =” backend.go:135“
tips:backend.go:135是:fmt.Printf(“%v”,resp),从watchChan收到resp]
func (e *EtcdClient) watchWithOptions(ctx context.Context, key string, opts ...clientv3.OpOption) clientv3.WatchChan {
if e.client == nil {
return nil
}
key = e.withPrefix(key)
return e.client.Watch(ctx, key, opts...)
}
// WatchPrefix watch the kvs change with same prefix
func (e *EtcdClient) WatchPrefix(ctx context.Context, prefix string) clientv3.WatchChan {
return e.watchWithOptions(ctx, prefix, clientv3.WithPrefix(), clientv3.WithPrevKV())
}
我不包括放置,删除事件,但实际输出是无效的空事件
package main
import (
"context"
"fmt"
"time"
clientv3 "go.etcd.io/etcd/clientv3"
)
func main() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: []string{"localhost:2379", "localhost:22379", "localhost:32379"},
DialTimeout: 5 * time.Second,
})
if err != nil {
// handle error!
}
defer cli.Close()
ctx := context.Background()
rch := cli.Watch(ctx, "foo")
for wresp := range rch {
for _, ev := range wresp.Events {
fmt.Printf("%s %q : %q\n", ev.Type, ev.Kv.Key, ev.Kv.Value)
}
}
}
如果您没有看到,请从文档中查看example
要进一步调试,您介意共享代码吗?