To Start Kafka Server
.\bin\windows\kafka-server-start.bat .\config\server.properties .\bin\windows\kafka-server-stop.bat .\config\server.properties
To Start Zookeeper Server
.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties .\bin\windows\zookeeper-server-stop.bat .\config\zookeeper.properties
Create Topic in Kafka with 5 Partition and Replication factor of 1
kafka-topics.bat --bootstrap-server localhost:9092 --topic firsttopic --create --partitions 5 --replication-factor 1
Note: Replication Factor cannot be more than 1 incase of localhost.
List Topics
kafka-topics.bat --bootstrap-server localhost:9092 --topic --list
Describe Topic
kafka-topics.bat --bootstrap-server localhost:9092 --topic firsttopic --describe
Delete Topic
kafka-topics.bat --bootstrap-server localhost:9092 --topic firsttopic --delete
Producer to push data into Topic in Kafka
kafka-console-producer.bat --broker-list localhost:9092 --topic test
Producer sending data into Topic as Key:Value pair
kafka-console-producer.bat --broker-list localhost:9092 --topic firsttopic --property parse.key=true --property key.separator=:
Note:
- Kafka Topic with same key would end in same Partition
- separator should be sent in command to diff between key and value
If you try to push data to a topic which doesn’t exist after 3 attempts the topic would be created.
Consumer to pull data from Topic in Kafka
kafka-console-consumer.bat --topic test --bootstrap-server localhost:9092 --from-beginning
{“Message”: “Hello World from Kafka”}