Last active
March 15, 2017 09:42
-
-
Save abhirockzz/fa138b873f7b907c7bd1fd4264ddd894 to your computer and use it in GitHub Desktop.
Using Kafka Streams state store in DSL and Processor API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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