A proof-of-concept (POC) project demonstrating the integration of Apache Kafka with Spring Boot. This repository contains the essential configurations and setups for quickly bootstrapping a Spring Boot application with Kafka capabilities.
This repository provides a proof-of-concept (POC) for integrating Apache Kafka with Spring Boot. Using the provided Docker Compose setup, you can quickly bootstrap a Kafka cluster and send/receive messages using the simple Spring Boot service.
- Docker and Docker Compose installed on your machine.
- Java 8+.
- Maven
1. Start the Kafka and Zookeeper services: docker-compose up -->This will start a Kafka broker and a Zookeeper instance using the provided docker-compose.yml configuration.
2. Run the Spring Boot application: mvn spring-boot:run
Once the application starts, it will connect to the Kafka broker running at localhost:29092.
3.Interacting with the Service You can send a message to the Kafka topic by making a POST request: POST /kafka/send Body: "Your message here" The received messages will be logged in the console of your Spring Boot application.
Code Overview KafkaProducer Service: A service that uses KafkaTemplate to send messages to a specified Kafka topic.
KafkaConsumer Service: A service that listens to a specified Kafka topic using the @KafkaListener annotation.
KafkaController: A REST controller that provides an endpoint for sending messages to Kafka.
curl command curl -X POST -H "Content-Type: application/json" -d '"Your message here"' http://localhost:8080/kafka/send
Postman Screenshot