Vertx Configuration via Zookeeper
You might find the docker-compose.yml, Dockerfile.zookeeper, zoo.cfg, and zookeeper-entrypoint.sh files to be useful in other projects where you want to quickly setup a Zookeeper service as the instructions for many of the docker images for Zookeeper are not very robust.
Table of contents
- ConfigurationGenerator.java - Generates "configrations" and loads them into Zookeeper periodically
- Constants.java - constants for the connection string and path in Zookeeper
- SimpleWebsiteMain.java - An example of the vert.x website that does not watch for updated "configs" in Zookeeper
- WebsiteMain.java - The vert.x website that does get updated "configs"
- ZookeeperVerticle.java - The vert.x Verticle(Service) that watches Zookeeper for configuration updates.
The directory is already set up for eclipse neon if you "Open Projects From Filesystem..."
If you do not have maven installed, you can build using docker:
mkdir .m2 docker run -it \ --rm \ --name maven-build \ -v "$PWD":/usr/src/myproject \ -v "$PWD"/.m2:/root/.m2 \ -w /usr/src/myproject \ maven:3-jdk-8 mvn package
- run in a docker image using an interactive pseudo-tty
- removing the container on exit
- name the container "maven-build"
- bind the current directory to a location inside the container so the build result can be saved outside the container
- bind the .m2 directory to the container's maven repository location so we only download the jars needed once to not waste network resources
- set the working directory in the container to the current directory outside the container
- Use a maven jdk-8 image and run maven to package a jar.
Running and Screenshots
You can now monitor the app in your terminal and use 127.0.0.1:8080, 127.0.0.1:8081, and 127.0.0.1:8082 to see the three webservers serve the latest configuration.
Other Operating Systems
You can now monitor the app in your terminal and use docker-machine-ip:8080, docker-machine-ip:8081, and docker-machine-ip:8082 to see the three webservers serve the latest configuration.
docker-compose run --rm zkcli -server zookeeper3
The Browser Result:
Pressing ctrl-c will should stop docker-compose but I would also recommend using docker-compose down before calling docker-compose a second time.
You can also test Zookeeper a bit by killing some of the zookeeper containers and seeing how the app responds.