Etcd watch mechanism

First, start etcd with docker

docker run -d\
  -p 2379:2379 \
  -p 2380:2380 \
  --name etcd \
  /usr/local/bin/etcd \
  --data-dir=/etcd-data --name node1 --listen-client-urls --advertise-client-urls --listen-peer-urls= --initial-advertise-peer-urls=

We add a key value pair to etcd

curl -XPUT -d value="Hello world"

Etcd’s watch monitoring can be divided into two types: one-time monitoring and continuous monitoring

One time monitoring

If an event is listened to, JSON data will be returned. After returning, the listener exits, and the listener needs to be started again later. Recursive is to listen for changes of all child nodes.


Then let’s change the value of key1

curl -XPUT -d value="changed value"

When the value of key1 changes, you can see that the previous wait process is over and listen for the return

Permanent monitoring. If an event is monitored, it will not exit and continue to return data. It is more reliable than one-time monitoring

Send a Message