In order to use Zookeeper to manage your project’s configurations across the cluster, first we will setup the zookeeper ensemble on our local machine (setup is for testing on a single machine) by following these steps:
1) Download a stable zookeeper release
2) Unpack it at three places and rename it to:
3) In order to use zookeeper we will need to setup configuration files for all servers.
Make a new file zoo.cfg,
and add following details:
4) Now we will have to define each server’s id by making a new file in:
which should have: 1
which should have: 2
which should have: 3
5) Next, we will start zookeeper ensemble for each server in 3 different terminals:
6) Now we will add some data in one of the ZNode of the zookeeper ensemble by following steps:
b) create /test_node “Some data”
7) Then we will write the following code in order to setup a watcher for zookeeper node so as to get stored data from zookeeper server using apache curator as a library to interact with our zookeeper server.
Add the following dependency in your build.sbt file:
and use this to interact with the zookeeper server: