Subscribing to Consul Key-Value

I’m trying to use Consul’s Key-Value API to pass a JSON configuration to an app running in one of my containers. It works great, but the API does not provide any pub-sub functionality (just read/write/delete) for a key.

So far, I managed to artificially compensate by using the Watch feature to restart the container whenever the key changes, but that leaves me with the need to

  • ASP.NET Core - Issues while Debugging through Docker in Visual Studio 2015
  • How to downgrade Docker on Mac to 1.12.x or connect to 1.12 hosts from 1.13 in Mac?
  • How to get `docker run` full arguments?
  • What special precautions must I make for docker apps running as pid 1?
  • Nginx dockerized accessing host IIS website on a given port
  • Where's docker's deamon.json? (missing)
    1. Externally configure Consul (either load a new configuration, or use the CLI, to specify a key to watch, and a shell script to run)
    2. Restart my app in mid-run – a good way to potentially lose data.

    Is there any programatic way (other than polling every x seconds) to get notified of a key change in Consul, or should I just back away from this solution, and move to Redis?

  • How do I install Nexus 3 in a Docker container with no internet connection?
  • Docker: skygear server not starting, connection refused
  • Error starting docker containers
  • Electron development on Windows using Docker?
  • how to schedule job with the monitoring of cpu,memory, disk io, etc.
  • Docker Mount Volume Directory with Install Files
  • One Solution collect form web for “Subscribing to Consul Key-Value”

    After a quick look at consul’s sources, it seems that the “watch” is a simple periodic pull. You could implement something similar in your code to achieve this.

    Periodic run of the watcher: https://github.com/hashicorp/consul/blob/master/watch/plan.go#L46

    KeyWatch Handler: https://github.com/hashicorp/consul/blob/master/watch/funcs.go#L29

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.