This repository contains an example project showcasing the usage of Spring Boot with Apache Kafka. It demonstrates how to integrate Kafka messaging in a Spring Boot application.
Before running this example, ensure that you have the following prerequisites:
- Java Development Kit (JDK) 17 or higher
- Apache Kafka installed and running (e.g., using Docker)
- Spring Boot version 3.1.1 or higher
To get started with this example, follow these steps:
-
Clone the repository:
git clone https://github.com/peirisabhi/springboot-kfka.git
-
Navigate to the project directory:
cd springboot-kfka -
Install and run Kafka using Docker:
docker-compose up -d
This command will start a Kafka broker, ZooKeeper, and create the necessary topics.
-
Build the project using build Maven.
-
Run the application:
./mvnw spring-boot:run
-
The application should now be running locally.
The Kafka configuration for this example can be found in the application.properties file. Make sure to update the configuration settings according to your Kafka setup.
# Kafka configuration
spring.kafka.bootstrap-servers=localhost:9092
spring.kafka.consumer.group-id=myGroup
spring.kafka.consumer.auto-offset-reset= earliest
spring.kafka.topic.name=topic1
spring.kafka.topic-json.name=topic_json
spring.kafka.consumer.key-deserializer= org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.value-deserializer= org.apache.kafka.common.serialization.StringDeserializer
#spring.kafka.consumer.value-deserializer= org.springframework.kafka.support.serializer.JsonDeserializer
spring.kafka.consumer.properties.spring.json.trusted.packages=*This example project includes a sample Kafka producer and consumer to demonstrate the usage of Kafka messaging with Spring Boot. The producer publishes messages to a Kafka topic, and the consumer listens to that topic to receive and process the messages.
Feel free to explore the code and modify it to suit your needs. The code is extensively documented to help you understand each step and the purpose of different components.
Contributions to this project are welcome. If you find any issues or have ideas for improvements, please open an issue or submit a pull request.
For any questions or feedback, please contact:
Abhishek Peiris
- Email: abhishekpeiris9@gmail.com
- GitHub: @peirisabhi