This repository demonstrates how to integrate Apache Kafka with Spring Boot. It covers Kafka producer, consumer, topic configuration, JSON serialization, and REST APIs for message publishing.
-
01-Initialization - Setting up Kafka in a Spring Boot project.
-
02-Consumer-Producer-Configuration - Configuring Kafka producer and consumer.
-
03-Kafka-Topic - Creating and managing Kafka topics.
-
04-Kafka-Producer - Implementing Kafka producers.
-
05-API-Send-Message - Sending messages using REST APIs.
-
06-Kafka-Consumer - Implementing Kafka consumers.
-
07-JSON-Serializer-Deserializer - Handling JSON messages with Kafka.
-
Java 17+
-
Apache Kafka
-
Spring Boot 3+
-
Docker (optional for containerized setup)
-
Start Kafka (if not running):
bin\windows\kafka-server-start.bat config\server.properties
-
Clone the repository:
git clone https://github.com/athrocks/Spring-Apache-Kafka.git cd Spring-Apache-Kafka
-
Run the Spring Boot application:
mvn spring-boot:run
Endpoint:
GET http://localhost:8080/api/v1/kafka/publish?message=hello%20world
Response:
"Message sent to the Kafka topic"
Endpoint:
POST http://localhost:8080/api/v1/kafka/publish
Request Body:
{
"id": 1,
"firstName": "John",
"lastName": "Doe"
}
Response:
"Json Message sent to the Kafka topic"
public class User {
private int id;
private String firstName;
private String lastName;
// Getters and Setters
}
This project is open-source and available under the MIT License.