projects
/
demos
/
kafka
/
wordcount
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
counter: 1.2.15 - Inlined the asserting ``Consumer``s
[demos/kafka/wordcount]
/
src
/
main
/
java
/
de
/
juplo
/
kafka
/
wordcount
/
counter
/
CounterStreamProcessor.java
diff --git
a/src/main/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessor.java
b/src/main/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessor.java
index
d64eb68
..
712ab65
100644
(file)
--- a/
src/main/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessor.java
+++ b/
src/main/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessor.java
@@
-1,15
+1,14
@@
package de.juplo.kafka.wordcount.counter;
package de.juplo.kafka.wordcount.counter;
-import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.common.serialization.Serdes;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.common.serialization.Serdes;
-import org.apache.kafka.streams.KafkaStreams;
-import org.apache.kafka.streams.KeyValue;
-import org.apache.kafka.streams.StreamsBuilder;
-import org.apache.kafka.streams.Topology;
+import org.apache.kafka.streams.*;
+import org.apache.kafka.streams.kstream.Consumed;
import org.apache.kafka.streams.kstream.KStream;
import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.Materialized;
import org.apache.kafka.streams.state.KeyValueBytesStoreSupplier;
import org.apache.kafka.streams.state.KeyValueBytesStoreSupplier;
-import org.apache.kafka.streams.kstream.*;
+import org.apache.kafka.streams.state.QueryableStoreTypes;
+import org.apache.kafka.streams.state.ReadOnlyKeyValueStore;
import java.util.Properties;
import java.util.Properties;
@@
-17,6
+16,9
@@
import java.util.Properties;
@Slf4j
public class CounterStreamProcessor
{
@Slf4j
public class CounterStreamProcessor
{
+ public static final String STORE_NAME = "counter";
+
+
public final KafkaStreams streams;
public final KafkaStreams streams;
@@
-24,14
+26,12
@@
public class CounterStreamProcessor
String inputTopic,
String outputTopic,
Properties properties,
String inputTopic,
String outputTopic,
Properties properties,
- KeyValueBytesStoreSupplier storeSupplier,
- ObjectMapper mapper)
+ KeyValueBytesStoreSupplier storeSupplier)
{
Topology topology = CounterStreamProcessor.buildTopology(
inputTopic,
outputTopic,
{
Topology topology = CounterStreamProcessor.buildTopology(
inputTopic,
outputTopic,
- storeSupplier,
- mapper);
+ storeSupplier);
streams = new KafkaStreams(topology, properties);
}
streams = new KafkaStreams(topology, properties);
}
@@
-39,8
+39,7
@@
public class CounterStreamProcessor
static Topology buildTopology(
String inputTopic,
String outputTopic,
static Topology buildTopology(
String inputTopic,
String outputTopic,
- KeyValueBytesStoreSupplier storeSupplier,
- ObjectMapper mapper)
+ KeyValueBytesStoreSupplier storeSupplier)
{
StreamsBuilder builder = new StreamsBuilder();
{
StreamsBuilder builder = new StreamsBuilder();
@@
-53,7
+52,7
@@
public class CounterStreamProcessor
.groupByKey()
.count(Materialized.as(storeSupplier))
.toStream()
.groupByKey()
.count(Materialized.as(storeSupplier))
.toStream()
- .map((word, count
) -> new KeyValue<>(word, WordCount.of(word, count
)))
+ .map((word, count
er) -> new KeyValue<>(word, WordCounter.of(word, counter
)))
.to(outputTopic);
Topology topology = builder.build();
.to(outputTopic);
Topology topology = builder.build();
@@
-62,6
+61,11
@@
public class CounterStreamProcessor
return topology;
}
return topology;
}
+ ReadOnlyKeyValueStore<Word, Long> getStore()
+ {
+ return streams.store(StoreQueryParameters.fromNameAndType(STORE_NAME, QueryableStoreTypes.keyValueStore()));
+ }
+
public void start()
{
log.info("Starting Stream-Processor");
public void start()
{
log.info("Starting Stream-Processor");