Kafka Streams Binding: Cannot get state store because the stream thread is PARTITIONS_ASSIGNED, not RUNNING

Viewed 1531

I use the infrastructure of Spring Cloud Stream Kafka Binding for stream processing.

Here is the main KafkaStream-methods:

private static final String READ_STORE_NAME = "readMessageStore";

  @Bean
public Consumer<KStream<String, ContentModel>> filter() {
    return in -> in.groupByKey(Grouped.with(Serdes.String(), new JsonSerde<>(ContentModel.class)))
            .reduce(this::mergeObjects, Materialized.as(READ_STORE_NAME));
}

private ContentModel mergeObjects(final ContentModel reducer, final ContentModel materialized) {      
    return reducer;
}

Configuration of binding:

spring.cloud.stream.bindings.filter-in-0:
     destination: topic

I deploy 2 instances of application, which separated by ApplicationId as follows:

spring.cloud.stream.kafka.streams.binder.functions.filter.applicationId = <Id>

But on the stage of deploy I receive:

IllegalStateException: Error when retrieving state store: j readMessageStore

Caused by: org.apache.kafka.streams.errors.InvalidStateStoreException: Cannot get state store readMessageStore because the stream thread is PARTITIONS_ASSIGNED, not RUNNING

From that Unable to open store for Kafka streams because invalid state I found out, that I need (apparently) to wait for the second RUNNING state before query.

But how can I set this delay in the Spring Cloud Stream Kafka Binding environment, considering that all state transitions in this case realized "under the hood"?

1 Answers

You need to enable the health indicator and then write the listener to monitor it for REBALANCE before the second RUNNING.

refer this Health Indicator

Related