Final Manual Practical 10 de
Final Manual Practical 10 de
EXPERIMENT NO :10
AIM: Stream data with Apache Kafka
OBJECTIVE: Understand Steps to read and write data using Kafka and Zookeeper.
PER-REQUISITES: Zookeeper and Apache kafka
Theory:
Kafka was developed at LinkedIn and is now an Apache project. You can find Kafka on the web at
http://kafka.apache.org. Kafka requires another application, ZooKeeper, to manage information.You can
install and build a ZooKeeper cluster on your own, but for this example, you will use the ZooKeeper
scripts provided by Kafka. To learn more about ZooKeeper, you can find it at
http://zookeeper.apache.org.
you will need to create three separate folders for Kafka. Use the following commands to create the
directories:
Each ZooKeeper instance needs an ID. It will look for a file named myid with an integer
value in it. In each folder, create the corresponding myid file with the correct value. The
following commands will create the file:
Configuring ZooKeeper and Kafka:
The configuration files for both ZooKeeper and Kafka are in the Kafka directory in the
conf folder. We have three Kafka directories, we will first using Kafka_1 and the steps will need to be
applied to every other directory.
2.Open New cmd from kafka folder and type following command to connect to Kafka.
C:\kafka>.\bin\windows\kafka-server-start.bat .\config\server.properties
3. Open new cmd from kafka folder and type following command for topic creation: Here we are
creating a topic named topic-example as shown below.
C:\kafka>.\bin\windows\kafka-topics.bat --create --topic topic-example --bootstrap-server
localhost:9092
Created topic topic-example.
4. In same cmd window start producer and type message to send to consumer as listed below.
C:\kafka>.\bin\windows\kafka-console-producer.bat --topic topic-example --bootstrap-server
localhost:9092
>hello world
>kafka topic event
>demo1
>demo2
(Press CTRL C to exit from Batch file)
>Terminate batch job (Y/N)? y
5. In same cmd window start consumer and read a message from producer listed below:
C:\kafka>.\bin\windows\kafka-console-consumer.bat --topic topic-example --from-beginning --
bootstrap-server localhost:9092
hello world
kafka topic event
demo1
demo2
Conclusion: Kafka and zookeeper are used generate topics. Topics are used used to stream data
between consumer and producer and send data is retrieved at consumer side.