Apache Kafka - Setup
Apache Kafka - Setup
of read and write, i.e. IO-related stuff. You can find more about Kafka on http://kafka.apache.org/.
Apache Kafka requires a running Zookeeper instance, which is used for reliable distributed
cordination.
Here we are using full-fledged zookeeper and not the one packaged with Kafka because it will be
single-node Zookeeper instance.
If you want you can run Kafka with packaged zookeeper located in Kafka package
inside \kafka\bin\windows directory.
Installation
A. JDK Setup
1. Start JRE installation and hit the check box “Change destination folder”, then click install.
2. Change the installation directory to any path without spaces in folder name. E.g.
C:\Java\jre1.8.0_xx\. (By default it will be C:\Program Files\Java\jre1.8.0_xx) then click Next.
3. Now open the system environment variables dialogue by opening Control Panel -> System
-> Advanced system settings -> Environment Variables.
4. Hit the New User Variable button in User variables section then type JAVA_HOME
in Variable name and give your jre path in Variable value.
7. Edit the path and type “;%JAVA_HOME%\bin” at the end of the text already written there
just like image below
8. To confirm the Java installation just open cmd and type “java –version”, you should be able
to see version of the java you just installed.
If your command prompt somewhat looks like the image above, you are good to go.
Otherwise you need to recheck whether your setup version is matching with the correct
OS architecture (x86, x64), or if the environment variables path is correct.
B. Zookeeper Installation
1. Goto your Zookeeper config directory. For me its C:\zookeeper-3.4.7\conf
3. Open zoo.cfg in any text editor like notepad but I prefer notepad++.
6. You can change the default Zookeeper port in zoo.cfg file (Default port 2181).
C. Setting Up Kafka
1. Go to your Kafka config directory. For me its C:\kafka_2.11-0.9.0.0\config
Also Kafka port & broker.id are configurable in this file. Leave other settings as it is.
5. Your Kafka will run on default port 9092 & connect to zookeeper’s default port which is
2181.
D. Running Kafka Server
Important: Please ensure that your Zookeeper instance is up and running before starting a
Kafka server.
2. Open a command prompt here by pressing Shift + right click and choose“Open command
window here” option)
.\bin\windows\kafka-server-start.bat .\config\server.properties
4. If everything went fine, your command prompt will look like this one:
5. Now your Kafka is up and running, you can create topics to store messages. Also we can
produce or consume data from Java or Scala code or directly from the command prompt.
E. Creating topics
1. Now create a topic with name “test” and replication factor 1, as we have only one Kafka
server running. If you have a cluster with more than 1 Kafka server running, you can increase
the replication-factor accordingly which will increase the data availability and act like a fault-
tolerant system.
6. Now type anything in the producer command prompt and press Enter, and you should be
able to see the message in the other consumer command prompt.
7. If you are able to push & see your messages in the consumer side, you are done with Kafka
setup.