In this tutorial we will learn using Apache Kafka High Level Producer API to send messages using Java Program.
Please make sure you have completed Apache Kafka Installation tutorial before you start this tutorial.
Step 1: Install JDK
Make sure you have JDK 1.7 or JDK 1.8 installed on your machine. You can download and install JKD 1.8 from this link.
Step 2: Install Eclipse IDE
Please install Eclipse IDE for Java EE Developers from this link.
Step 3: Create Maven Project with Eclipse
Please create a maven project in eclipse. File >> New >> Other >> Maven >> Maven Project. In the New Maven Project wizard select the check box for creating a simple project.
In the next screen populate the groupId and ArtificatId for your maven project.
Step 4: Configure Maven for Kafka in Pom.xml
Add the following dependency jar files to your Maven Pom.xml file
Step 5: Create Producer Code using Kafka API
code snippets as below. Please use both the classes below in the same package.
Step 6: Set Run Configurations to produce the messages
Run the Java Program and you will see the following output on the console:
Step 7: Check via command line if messages are available on the topic.