Created
December 13, 2017 16:08
-
-
Save kiview/f1554d7089d3a253c83fd7c03c2e60b3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@Bean | |
KTable reportStream(StreamsBuilder builder, Engine engine) { | |
def stream = builder.stream(topic) | |
.groupBy({ key, word -> word }) | |
.windowedBy(SessionWindows.with(TimeUnit.SECONDS.toMillis(1))) | |
.aggregate( | |
new Initializer<Long>() { | |
@Override | |
Long apply() { | |
0 | |
} | |
}, | |
new Aggregator<String, String, Long>() { | |
@Override | |
Long apply(String key, String value, Long aggregate) { | |
def l = 1 + aggregate | |
return l | |
} | |
}, | |
new Merger() { | |
@Override | |
Long apply(Object aggKey, Object aggOne, Object aggTwo) { | |
return aggOne + aggTwo | |
} | |
}, | |
Materialized.with(Serdes.String(), Serdes.Long())) | |
stream.toStream().to("classificationResult") | |
stream | |
} | |
@Bean | |
KStream classificationStream(StreamsBuilder builder, Engine engine) { | |
builder.stream("classificationResult").mapValues({ | |
println "classResult" | |
println it | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment