Search⌘ K
AI Features

Classic Integration: Topology and State Store

Explore how to integrate Kafka Streams with Spring Boot by creating a stateful topology that concatenates messages by key and stores them in a state store. Discover how to expose and query this state store via a REST API, utilizing Spring Boot's dependency injection and KafkaStreams instance management.

Topology creation

With the dependencies, configuration, and topics set up, we can create our topology. We will create a new class and annotate it with @Component. This annotation marks the class for Spring Boot to be managed as a bean, meaning Spring Boot is in charge of the life cycle of this class. Spring boot will instantiate this class and inject the required dependencies it has.

The topology itself will be created inside a method accepting a StreamsBuilder instance. The method should be annotated with @Autowired, indicating that its arguments are automatically injected by Spring Boot. With the StreamsBuilder, creating the topology is no different than creating it in a ...