This Kafka Stream Application demonstrates a stream processing setup using Spring Kafka. It defines Kafka producers, Kafka Stream processing topology, and other necessary configurations for stream processing.
Event1
andEvent2
: Represent the events to be processed.JoinedEvent
: Represents the result of joiningEvent1
andEvent2
.CompositeKey
: Custom key used for joining.
- Kafka Producer Configurations: Setup for producing
Event1
andEvent2
. - Kafka Streams Configurations: Setup for processing streams and joining events.
- Topics: Topic configurations for
X
andY
topics.
The stream processing topology is defined in the kStream
bean method within KafkaConfig
. It reads from topics X
and Y
, joins the events on a composite key, and writes the resulting JoinedEvent
to the joined-topic
.
- Kafka Cluster: Ensure you have a running Kafka cluster.
- Application Properties: Set the necessary properties in
application.properties
orapplication.yml
for Kafka bootstrap servers and other configurations. - Build and Run: Build and run the application using your preferred IDE or from the command line with Maven or Gradle.
- Produce Events: Events of type
Event1
andEvent2
are produced to topicsX
andY
respectively using the configured Kafka templates. - Stream Processing: The application's Kafka Streams topology will continuously process the incoming events, join them, and produce the resulting
JoinedEvent
to thejoined-topic
. - Inspect Results: You can inspect the results by consuming from the
joined-topic
using a Kafka consumer.
The main code structure is organized as follows:
src/main/java/com/example/kafkastreamapp
contains the main application configurations and stream processing setup.src/main/java/com/example/kafkastreamapp/Models
contains the DTO classes for the events.src/main/resources
contains theapplication.properties
orapplication.yml
file for configuring the Kafka bootstrap servers and other application configurations.
# Using Gradle
gradle bootRun