How thepracticaldeveloper/kafka-spring-boot-example works
Project type and purpose
• This is a single-module Spring Boot back-end demo application whose sole purpose is to illustrate how to configure a Kafka producer and a consumer group (with three consumers) using Spring Boot’s auto-configuration.
File structure
• Top-level files:
• pom.xml (Maven build)
• docker-compose.yml (defines Kafka broker + ZooKeeper)
• README.md + img/ (documentation)
• src/main/java/io/tpd/kafkaexample:
• KafkaExampleApplication.java (Spring Boot entry point)
• HelloKafkaController.java (REST controller that publishes messages)
• PracticalAdvice.java (service/bean that sends messages to Kafka)
• src/main/resources/application.yml (Kafka producer/consumer config: serializers, topic, group, partitions)
• src/test/java/... (standard Spring Boot integration test)
README for additional insights
• It describes three serialization types (JSON→POJO, plain String, byte[])
Main components
a. Spring Boot Application
– Controller Layer (HelloKafkaController)
– Service/Producer Bean (PracticalAdvice)
– Consumer Beans (three separate listeners in the same application, each in the same consumer group)
b. Apache Kafka Cluster
– Topic with three partitions
– ZooKeeper (for broker leadership election)
c. Docker Compose (external service orchestration)
d. Clients (e.g., curl or Postman) that send HTTP POST requests to the REST endpoint
Relationships and interactions
1. Client → HTTP POST → Spring Boot’s HelloKafkaController
2. Controller calls PracticalAdvice to format and send a message
3. PracticalAdvice autowired KafkaTemplate publishes to my-topic
4. Kafka distributes messages across 3 partitions
5. The Consumer Group (3 parallel listener beans) each receives messages from assigned partitions
6. Consumer beans process and log or further propagate the data
Architectural patterns & design principles
• Layered architecture (Controller → Service → Messaging)
• Asynchronous communication via Kafka (pub/sub)
• Consumer group parallelism (scalability)
• Externalized configuration (application.yml + Docker Compose)