Simple Kafka Producer-Consumer Application With Spring
-
Download kafka binary
-
Run the zookeeper & kafka server (scripts found in kafka folder)
bin/windows/zookeeper-server-start.bat config/zookeeper.properties bin/windows/kafka-server-start.bat config/server.properties
in config/server.properties file, add the following line if missing from file
listeners=PLAINTEXT://127.0.0.1:9092
-
Create topics using kafka CLI
bin/windows/kafka-topics.bat --create --zookeeper <zookeeperServerAddr> --replication-factor <replicationFactor> --partitions <numberPartitions> --topic <topicName>
Example:
bin/windows/kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic odd
-
Create & compile the project
-
Run the program
bin/windows/kafka-topics.bat --list --zookeeper <zookeeperAddr>
bin/windows/kafka-console-consumer.bat --bootstrap-server <brokerAddr> --topic <topicName>
bin/windows/kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic topicA