1. Configure Zookeeper



Kafka relies on Zookeeper to run, so you need to install and run Zookeeper before running Kafka.



1.1 download the installation files: http://mirror.bit.edu.cn/apache/zookeeper/







The version selected here is 3.5.2.



1.2 Unzip files (this article unzip to D:\kafka)







1.3 Open D:\kafka\zookeeper-3.5.2-alpha\zookeeper-3.5.2-alpha\conf and rename zoo_sample. CFG to zoo.cfg







1.4 Open zoo.cfg from the text editor







1.5 Changing the dataDir and dataLogDir saving paths



dataDir=D:\data\logs\zookeeper 

dataLogDir=D:\data\logs\zookeeper 







(2) Configure Kafka



2.1 Downloading the Installation File: http://kafka.apache.org/downloads.html









2.2 Unzip files (this article unzip to D:\kafka)



2.3 Open D:\kafka\kafka_2.12-0.11.0.1\kafka_2.12-0.11.0.1\config\server.properties and modify log.dirs











3. Start Zookeeper and Kafka



Go to Zookeeper D:\kafka\zookeeper-3.5.2-alpha\zookeeper-3.5.2-alpha\bin, open CMD, and run zkserver. CMD.







3.2, go to KafKa D:\ KafKa \kafka_2.12-0.11.0.1\kafka_2.12-0.11.0.1\bin\ Windows, open CMD and run the following command



[html]
view plain
copy
print
?

  1. .\kafka-server-start.bat .. \.. \config\server.properties
.\kafka-server-start.bat .. \.. \config\server.propertiesCopy the code


The following command is successfully executed:







Test Kafka



4.1. Create topics



In the D:\kafka\kafka_2.12-0.11.0.1\kafka_2.12-0.11.0.1\bin\ Windows folder, “Shift+ right mouse click on the blank area to open the command prompt window



[html]
view plain
copy
print
?

  1. .\kafka-topics.bat –create –zookeeper localhost:2181 –replication-factor 1 –partitions 1 –topic test  
.\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic testCopy the code










4.2. Create a Producer

In the D:\kafka\kafka_2.12-0.11.0.1\kafka_2.12-0.11.0.1\bin\ Windows folder, “Shift+ right mouse click on the blank area to open the command prompt window

[html]
view plain
copy
print
?

  1. .\kafka-console-producer.bat –broker-list localhost:9092 –topic test  
.\kafka-console-producer.bat --broker-list localhost:9092 --topic test
Copy the code






4.3 create a Consumer

In the D:\kafka\kafka_2.12-0.11.0.1\kafka_2.12-0.11.0.1\bin\ Windows folder, “Shift+ right mouse click on the blank area to open the command prompt window

[html]
view plain
copy
print
?

  1. .\kafka-console-consumer.bat –zookeeper localhost:2181 –topic test  
.\kafka-console-consumer.bat --zookeeper localhost:2181 --topic testCopy the code








Note: Do not close the Windows opened above



You can then enter a message in the Producer console window. Soon after the message is entered, the Consumer window displays the message sent by the Producer: