Ecwid / consul-api

Java client for Consul HTTP API
Apache License 2.0
416 stars 177 forks source link

Blocking query #136

Open shekhar2709 opened 6 years ago

shekhar2709 commented 6 years ago

Does consul-api support consul blocking query. Can someone point me to right api's here. I need to have watches over my keys in kv store.

shekhar2709 commented 6 years ago

@vgv OrbitzWorldwide/consul-client does have something similar. I was expecting something on similar lines.

           KVCache kvCache = KVCache.newCache(consul.keyValueClient(), key, 30);

    kvCache.addListener(new ConsulCache.Listener<String, Value>() { 
        public void notify(Map<String, Value> map) { 
            System.out.println("Got change notification");
            //o.notifyAll();
        } 
    });
fswansonGohealth commented 6 years ago

Just use the list return signature and supply the index that is the uppermost index under the key. ex. assuming uppermost index is 25 for prefix queue curl -X GET 'http://localhost:8500/v1/kv/queue?recurse=true&index=25'

The key is to supply the correct index ... otherwise the query will return immediately. Also important to note that all the complexities of long running queries over http apply.