projects
/
demos
/
kafka
/
wordcount
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
query: 2.0.0 - (RED) The keys of the top10-topic are deserialized as JSON
[demos/kafka/wordcount]
/
src
/
main
/
java
/
de
/
juplo
/
kafka
/
wordcount
/
query
/
QueryStreamProcessor.java
diff --git
a/src/main/java/de/juplo/kafka/wordcount/query/QueryStreamProcessor.java
b/src/main/java/de/juplo/kafka/wordcount/query/QueryStreamProcessor.java
index
4749264
..
bf27e2d
100644
(file)
--- a/
src/main/java/de/juplo/kafka/wordcount/query/QueryStreamProcessor.java
+++ b/
src/main/java/de/juplo/kafka/wordcount/query/QueryStreamProcessor.java
@@
-5,6
+5,7
@@
import jakarta.annotation.PreDestroy;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.common.serialization.Serdes;
import org.apache.kafka.streams.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.common.serialization.Serdes;
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.KTable;
import org.apache.kafka.streams.kstream.Materialized;
import org.apache.kafka.streams.kstream.KStream;
import org.apache.kafka.streams.kstream.KTable;
import org.apache.kafka.streams.kstream.Materialized;
@@
-57,13
+58,17
@@
public class QueryStreamProcessor
StreamsBuilder builder = new StreamsBuilder();
KTable<String, User> users = builder
StreamsBuilder builder = new StreamsBuilder();
KTable<String, User> users = builder
- .stream(usersInputTopic)
+ .stream(
+ usersInputTopic,
+ Consumed.with(Serdes.String(), new JsonSerde().copyWithType(User.class)))
.toTable(
Materialized
.<String, User>as(userStoreSupplier)
.withKeySerde(Serdes.String())
.withValueSerde(new JsonSerde().copyWithType(User.class)));
.toTable(
Materialized
.<String, User>as(userStoreSupplier)
.withKeySerde(Serdes.String())
.withValueSerde(new JsonSerde().copyWithType(User.class)));
- KStream<String, Ranking> rankings = builder.stream(rankingInputTopic);
+ KStream<String, Ranking> rankings = builder
+ .<Key, Ranking>stream(rankingInputTopic)
+ .map((key, value) -> new KeyValue<>(key.getUsername(), value));
rankings
.join(users, (ranking, user) -> UserRanking.of(
rankings
.join(users, (ranking, user) -> UserRanking.of(
@@
-73,6
+78,7
@@
public class QueryStreamProcessor
.toTable(
Materialized
.<String, UserRanking>as(rankingStoreSupplier)
.toTable(
Materialized
.<String, UserRanking>as(rankingStoreSupplier)
+ .withKeySerde(Serdes.String())
.withValueSerde(new JsonSerde().copyWithType(UserRanking.class)));
Topology topology = builder.build();
.withValueSerde(new JsonSerde().copyWithType(UserRanking.class)));
Topology topology = builder.build();