Kafka-Java-Maven

Here is a step-by-step guide to create a Java Maven project for implementing Apache Kafka:

Note : Make sure to have Java & Maven install on your machine

1. Create a Maven project: Open your terminal or command prompt and navigate to the directory where you want to create the project. Run the command mvn archetype:generate -DgroupId=com.example -DartifactId=kafka-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false. This will create a Maven project with the name kafka-project in the directory com.example.

2. Add Kafka dependencies to the pom.xml file: Open the pom.xml file in the project directory and add the following dependencies:

3. Create a Kafka producer: In your project, create a new Java class for the producer. For example, you can name it KafkaProducerExample.java. Add the following code to the class:

4. Create a Kafka consumer: In your project, create a new Java class for the consumer. For example, you can name it KafkaConsumerExample.java. Add the following code to the class:

Note: In the example above, you will need to replace localhost:9092 with the actual address of your Kafka broker.

You can now run the producer and consumer classes to see the messages being produced and consumed in your Kafka cluster.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top