How to setup and use zookeeper in scala using Apache Curator

Table of contents
Reading Time: 2 minutes

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:

/home/user/Desktop/zookeeper2/conf/zoo.cfg, as:

/home/user/Desktop/zookeeper3/conf/zoo.cfg, as:

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:

cd /home/user/Desktop/zookeeper1
bin/ start

cd /home/user/Desktop/zookeeper2
bin/ start

cd /home/user/Desktop/zookeeper3
bin/ start

6) Now we will add some data in one of the ZNode of the zookeeper ensemble by following steps:

a) bin/
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:

Written by 

Sidharth is a Lead Consultant, having experience of more than 4.5 years. He has started working on Scala and Clojure and is actively involved in other developmental work. He enjoys working in a team and believes that knowledge is something that should be shared openly and on a large scale. As an avid gamer and passionate player, he likes to be involved in both indoor and outdoor activities.

1 thought on “How to setup and use zookeeper in scala using Apache Curator2 min read

  1. If I want to automate server additions and dynamically add them to Zookeeper’s ensemble, then measure the time it takes for all servers to recognize each other, is Curator or Kazoo the right tools to use?

Comments are closed.