How yoandypv/spring-boot-kafka-basics works
Project Type and Purpose
• This is a microservices demo consisting of two independent Spring Boot applications (“Customers” and “Notifications”) that communicate asynchronously via Apache Kafka.
• The “Customers” service exposes a REST API to create new customers. Upon creation, it publishes a CustomerCreatedEvent to a Kafka topic. The “Notifications” service consumes that event to perform further processing (e.g., sending emails, logging, etc.).
File‐structure Analysis
• Top level: README.md, plus two sibling folders: customers/ and notifications/.
• Each folder is a standalone Maven + Spring Boot project, with the usual Maven wrapper and pom.xml.
• Inside each service:
• config/ (Kafka producer/consumer configuration)
• entity/ (Customer domain object)
• events/ (shared event definitions: Event, EventType, CustomerCreatedEvent)
• service/ (business logic + event publishing or consuming)
• web/ (for Customers: REST controller)
• No database or repository layers are present, so state persistence is out of scope in this example.
Insights from README
• Confirms the roles: Customers = Kafka producer, Notifications = Kafka consumer.
• Goal is to illustrate asynchronous communication between microservices.
a. Main Components
• Customers Service
• REST API (CustomerController)
• Business Logic (CustomerService)
• Event Publisher (CustomerEventsService + KafkaProducer)
• Apache Kafka Cluster (brokers + topics; optionally Zookeeper)
• Notifications Service
• Kafka Consumer (CustomerEventsService + KafkaConsumer)
• Processing Logic (could represent NotificationService)
b. Relationships and Data Flow
1. Client → Customers Service (HTTP POST /customers)
2. Customers Service handles request → CustomerController → CustomerService
3. CustomerService invokes CustomerEventsService → serializes event
4. KafkaProducer sends CustomerCreatedEvent to customer.events topic
5. Notifications Service’s KafkaConsumer subscribes to same topic
6. On event arrival → NotificationEventHandler processes the event
c. Architectural Patterns and Principles
• Microservices pattern: two loosely coupled Spring Boot applications
• Asynchronous messaging via event-driven architecture
• Single responsibility: each service has its own bounded context
• Shared kernel for event definitions to enforce schema compatibility
d. Key Technologies
• Java + Spring Boot
• Apache Kafka (producers + consumers configured via KafkaProducerConfig / KafkaConsumerConfig)
• Maven build system
• JSON or Avro (depending on configuration) for event serialization