Example Kafka Producer and Consumer apps.
Article: https://www.javaworld.com/article/3060078/big-data/big-data-messaging-with-kafka-part-1.html
Source: https://github.com/denisecase/kafka-api
- OpenJDK or JDK (8 or up)
- Apache Zookeeper, installed and working
- Apache Kafka, installed and working
Change server.properties file
From:
log.dirs=/tmp/kafka-logs
To:
log.dirs=tmp/kafka-logs
Start Zookeeper service as you did previously.
Start Kafka service.
Create a Kafka topic.
Open PowerShell as Administrator in the root project folder, compile the code using Maven and create an executable jar file. Generated artificacts can be found in the new 'target' folder.
mvn clean compile assembly:single
Open PowerShell as Administrator in the root project folder, start the original consumer app using topic test and group1 with:
java -cp target/kafka-api-1.0-SNAPSHOT-jar-with-dependencies.jar com.spnotes.kafka.simple.Consumer test group1
Open a new PowerShell as Administrator in the root project folder, start the Producer app using topic test:
java -cp target/kafka-api-1.0-SNAPSHOT-jar-with-dependencies.jar com.spnotes.kafka.simple.Producer test
java -cp target/kafka-api-1.0-SNAPSHOT-jar-with-dependencies.jar com.spnotes.kafka.simple.ProducerHello test
java -cp target/kafka-api-1.0-SNAPSHOT-jar-with-dependencies.jar com.spnotes.kafka.simple.ProducerSentence test
java -cp target/kafka-api-1.0-SNAPSHOT-jar-with-dependencies.jar com.spnotes.kafka.simple.ProducerSentenceRandom test
- Type some messages for the Producer.
- Verify the messages are output by the Consumer.
http://cloudurable.com/blog/kafka-tutorial-kafka-producer/index.html
Setting your system environment variables is important when running Windows and using Linux-based tools.
To edit:
-
Hit the Windows key and type "Edit the System Environment Variables" until it appears.
-
Click on the menu option to open it.
-
Click "Environment Variables" button.
-
There are two areas. Don't use the top "user variables" - use the "Systemv variables" below.
-
They are alphabetical - scroll to verify each entry uses the path on your machine.
Here's how to edit the Path variable.
Here's the entries you should see.