From: Kai Moritz Date: Sun, 9 Jun 2024 08:52:25 +0000 (+0200) Subject: query: 1.0.6 - Refined `QueryStreamProcessor` X-Git-Tag: query-with-kafkaproducer~15 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=5c3e257b49dbcabc0fadc7fd335dcfc4ba57c6ef;p=demos%2Fkafka%2Fwordcount query: 1.0.6 - Refined `QueryStreamProcessor` -- store name is a constant --- 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 2d3d4c8..15b28db 100644 --- a/src/main/java/de/juplo/kafka/wordcount/query/QueryStreamProcessor.java +++ b/src/main/java/de/juplo/kafka/wordcount/query/QueryStreamProcessor.java @@ -25,9 +25,10 @@ import java.util.Properties; @Slf4j public class QueryStreamProcessor { + public static final String STORE_NAME = "rankings-by-username"; + public final KafkaStreams streams; public final HostInfo hostInfo; - public final String storeName = "rankingsByUsername"; public final StoreQueryParameters> storeParameters; public final ObjectMapper mapper; @@ -63,17 +64,17 @@ public class QueryStreamProcessor throw new RuntimeException(e); } }) - .toTable(Materialized.as(storeName)); + .toTable(Materialized.as(STORE_NAME)); streams = new KafkaStreams(builder.build(), props); hostInfo = applicationServer; - storeParameters = StoreQueryParameters.fromNameAndType(storeName, QueryableStoreTypes.keyValueStore());; + storeParameters = StoreQueryParameters.fromNameAndType(STORE_NAME, QueryableStoreTypes.keyValueStore());; this.mapper = mapper; } public Optional getRedirect(String username) { - KeyQueryMetadata metadata = streams.queryMetadataForKey(storeName, username, Serdes.String().serializer()); + KeyQueryMetadata metadata = streams.queryMetadataForKey(STORE_NAME, username, Serdes.String().serializer()); HostInfo activeHost = metadata.activeHost(); log.debug("Local store for {}: {}, {}:{}", username, metadata.partition(), activeHost.host(), activeHost.port());