Search code examples
consulspring-cloud-consulconsul-kvconsul-health-check

Configure Consul Watches with HTTP Endpoint Handler through CLI


I am starting out with Consul, and I was wondering if there is a way to set the HTTP handler configuration(s) (i.e. path, method, etc.) through the CLI command itself (consul watch), without using a configuration file (with -config-file argument).

Thanks.


Solution

  • In addition to defining Consul watches in the agent configuration, you can directly execute watches using the consul watch CLI. For example,

    $ consul watch -type=key -key=foo/bar/baz /usr/bin/my-key-handler.sh
    

    Additional examples of defining watches either in the agent config, or the CLI, can be found at https://www.consul.io/docs/dynamic-app-config/watches.

    The CLI, however, only supports executing script handlers. It is not possible to configure the consul watch CLI to use an HTTP handler. HTTP handlers can only be used when watches are defined in the agent configuration.