Updated : I misunderstood OP's question from "how to check if the Topology has finished materialized the input topic to state store" to "state store restore process"
You can only get KeyValueStore from your KafkaStreams instance when the KafkaStreams' state has changed from REBALANCING
to RUNNING
state.
You can check this this state transition using a StreamsBuilderFactoryBeanCustomizer
to access the underlying KafkaStreams instance.
If you just want to check when all state store have been fully populated and when kafka stream thread is ready so you can get a KeyValueStore
the you can listen on StateListener
:
@Bean
public StreamsBuilderFactoryBeanCustomizer onKafkaStateChangeFromRebalanceToRunning() {
return factoryBean -> factoryBean.setStateListener((newState, oldState) -> {
if (newState == KafkaStreams.State.RUNNING && oldState == KafkaStreams.State.REBALANCING) {
// set flag that `stateStore` store of current KafkaStreams has been fully restore
// then you can get
}
}
}
or if you want to get the store from KafkaStreams
instance
@Bean
public StreamsBuilderFactoryBeanCustomizer streamsBuilderFactoryBeanCustomizer() {
return factoryBean -> factoryBean.setKafkaStreamsCustomizer((KafkaStreamsCustomizer) kafkaStreams -> {
kafkaStreams.setStateListener((newState, oldState) -> {
if (newState == KafkaStreams.State.RUNNING && oldState == KafkaStreams.State.REBALANCING) {
//get and assign your store using kafkaStreams.store("stateStore", QueryableStoreTypes.keyValueStore());
//and set flag that `stateStore` store of current KafkaStreams has been fully restore
}
});
});
}
Read more in the docs.
Note that there should be only one instance of StreamsBuilderFactoryBeanCustomizer.