Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use etcd v3 restful api to watch

Tags:

rest

api

etcd

etcd3

i am trying to watch key with etcdv3 restful api,following etcd/Documentation/dev-guide/api_grpc_gateway.md,but it seems not work well with watch.

 curl http://localhost:2379/v3beta/watch \
      -X POST -d '{"create_request": {"key":"Zm9v"} }'

 curl http://localhost:2379/v3beta/watch \
      -X POST -d '{"create_request": {"key":"Zm9v"} }'
 #{"header":{"cluster_id":"7016043442779247867","member_id":"5993310732371594633","revision":"2","raft_term":"2"}}

the watch will not have a response.

this is my docker-compose.yml:

version: "3"

services:
    etcd:
        image: quay.io/coreos/etcd:latest
        command: >
            /usr/local/bin/etcd
            --name node1
            --initial-advertise-peer-urls http://${HOST}:2380
            --listen-peer-urls http://0.0.0.0:2380
            --advertise-client-urls http://${HOST}:2379
            --listen-client-urls http://0.0.0.0:2379
            --initial-cluster node1=http://${HOST}:2380
            --debug
        expose:
            - 2379
            - 2380
        ports:
            - "2379:2379"
            - "3380:2380"
like image 705
He Cheng Avatar asked Nov 08 '22 07:11

He Cheng


1 Answers

Try this instead:

$ curl --no-buffer http://localhost:2379/v3beta/watch \
      -X POST -d '{"create_request": {"key":"Zm9v"} }'

Also refer to this awesome article: HTTP Streaming (or Chunked vs Store & Forward)

like image 140
RussellLuo Avatar answered Nov 15 '22 04:11

RussellLuo