Apache Kakfa Producer Consumer using Java 8
This is a producer consumer application using Kafka
Prerequsities;
- Download Zookeeper. Configure the config/zookeeper.properties file. zookeeper is required for kafka to run. Zookeeper will store the kafka configurations
- Download Kafka. Configure the config/server.properties
#zookeeper start
zookeeper-server-start.bat config/zookeeper.properties
runs on port 2181
#kafka start
kafka-server-start.bat config/server.properties
#create multiple copies of server.properties and run them separately for multi broker kafka application
runs on port 9092
#Steps
- Create a topic
- Configure the producer with bootstrapServerHost = "127.0.0.1:9092";
- Create a producer with key ProducerRecord<String,String> record = new ProducerRecord<String, String>(topic,key,value); All the records with same key goes to the same partition
- Configure the consumer with bootstrapServerHost = "127.0.0.1:9092";
- Subscribe consumer to the topic
- Run the producer application to publish the data to kafka
- Run the consumer application to consume the data from kafka