Chris
Chris

Reputation: 1349

Accessing Kafka Stream State Store with Spring

Referencing 4.2.6 of this doc https://docs.spring.io/spring-kafka/reference/htmlsingle/#kafka-streams

How do you get access to state stores using kafka stream spring support?

Without spring you could do?

StreamsBuilder builder = ...;
// Start an instance of the topology
KafkaStreams streams = new KafkaStreams(builder, config);

...

// Get the key-value store CountsKeyValueStore
ReadOnlyKeyValueStore<String, Long> keyValueStore =
    streams.store("CountsKeyValueStore", QueryableStoreTypes.keyValueStore());

But I am not sure how to gain acess to KafkaStreams object.

Upvotes: 3

Views: 2300

Answers (1)

Gary Russell
Gary Russell

Reputation: 174829

Autowire the StreamsBuilderFactoryBean (or otherwise get a reference to it from the application context) and call getKafkaStreams().

Upvotes: 6

Related Questions