Need to use watches for an use key value store consul

I am new to consul. Actually i have usecase where i need to add a watch to particular key in consul keystore, if there i an change to the value for that key consul should notify. I Read about watches in consul, i am still confused if consul supports this kind of behavior. Can anybody point me to an example if this possible.

I think it’s documented very well:

You could execute a script which will be triggered and notifies you:
consul watch -type=key -key=foo/bar/baz /usr/bin/

Yeah correct I went through this document. The issue is I have an Java code which need to do this that code needs some kind of event to act on.

Something like consul writes a file, your Java app is looking for it and reacts if it’s present or content is “x”? Kind of a signal or trigger file?

Something like AWS S3 object notification. Okk one question. does consul have some hash on the key. Like if the value for the key changes the hash for that key changes , something like the value of if-match header in terms of REST

Hi @sparshneel,

Watches on key-values just use Blocking Queries under the hood. If you’re using the API to directly perform a blocking query, then the API will only return when the KV you’re watching is modified (or if the timeout is reached – in which case you retry the query). Similarly, the Watch will only fire the key’s value is modified.

Does this help answer how you can monitor a particular KV for changes?