docker-compose up
- Observe the output of all containers
- Note that watchers are set for
/election
path and each zNode it finds will trigger a watcher notification
- Open http://localhost/list or
curl http://localhost:80/list
curl -X POST http://localhost/terminate
will send a request to one of the application servers- Nginx will round robin and select one of the application servers available (3 initially)
- The application server that receives the request will close the Zookeeper client, terminating the ephemeral zNode that is placed under
/election
- Verify via container output that all of the other Zookeeper instances have gotten the notification. It might look something like:
Got watcher event: NODE_CHILDREN_CHANGED[4]@/election
- You should now see that the number of zNode children under
/election
is fewer than before
- If a host goes down, other hosts can get notified. One of the hosts can then be chosen as the new leader. If the original host comes back up later, the host can re-join the pool and is no longer the leader.
- If you have a pool of servers and you want to give back to the requester the best server based on geographic distance, or connection type (i.e. Websockets)