Skip to content

Instantly share code, notes, and snippets.

@abhirockzz
Last active March 15, 2017 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhirockzz/fa138b873f7b907c7bd1fd4264ddd894 to your computer and use it in GitHub Desktop.
Save abhirockzz/fa138b873f7b907c7bd1fd4264ddd894 to your computer and use it in GitHub Desktop.
Using Kafka Streams state store in DSL and Processor API
//DSL API
KStream<String,Double> streamFromKafka = ....; // from kafka topic
KGroupedStream<String,Double> groupedStream = streamFromKafka.groupByKey();
//options
groupedStream.count(inMemoryKVFactory); OR
groupedStream.count(persistentKVFactory); OR
//Processor API - use TopologyBuilder to associate state stores
TopologyBuilder builder = new TopologyBuilder();
//options
builder.addStateStore(inMemoryKVFactory, "processor-1"); OR
builder.addStateStore(persistentKVFactory, "processor-1");
//get a handle to the store using ProcessorContext
ProcessorContext pc = ... ;
KeyValueStore<String, Double> kvStateStore = (KeyValueStore<String, Double>) pc.getStateStore("my-state-store");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment