From: Kai Moritz Date: Sat, 4 Sep 2021 15:35:53 +0000 (+0200) Subject: query:1.0.2 - Fixed responses for availability edge-cases X-Git-Tag: query-1.0.2 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=0d1ed8c65f422e5c0cd291c35dba67b1f2205997;p=demos%2Fkafka%2Fwordcount query:1.0.2 - Fixed responses for availability edge-cases * No invalid redirect, if the host-info ist not available * 503 Service Temporarily Unavailable, while streams is not ready --- diff --git a/pom.xml b/pom.xml index 2dd080b..56a2b76 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ de.juplo.kafka.wordcount query - 1.0.1 + 1.0.2 Wordcount-Query Query stream-processor of the multi-user wordcount-example diff --git a/src/main/java/de/juplo/kafka/wordcount/query/QueryController.java b/src/main/java/de/juplo/kafka/wordcount/query/QueryController.java index 0c7dc31..a9b5b80 100644 --- a/src/main/java/de/juplo/kafka/wordcount/query/QueryController.java +++ b/src/main/java/de/juplo/kafka/wordcount/query/QueryController.java @@ -1,6 +1,7 @@ package de.juplo.kafka.wordcount.query; import lombok.RequiredArgsConstructor; +import org.apache.kafka.streams.errors.InvalidStateStoreException; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -30,6 +31,13 @@ public class QueryController .build(); } - return ResponseEntity.of(processor.getUserRanking(username)); + try + { + return ResponseEntity.of(processor.getUserRanking(username)); + } + catch (InvalidStateStoreException e) + { + return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).build(); + } } } 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 f7dc750..696e088 100644 --- a/src/main/java/de/juplo/kafka/wordcount/query/QueryStreamProcessor.java +++ b/src/main/java/de/juplo/kafka/wordcount/query/QueryStreamProcessor.java @@ -99,7 +99,7 @@ public class QueryStreamProcessor HostInfo activeHost = metadata.activeHost(); log.debug("Local store for {}: {}, {}:{}", username, metadata.partition(), activeHost.host(), activeHost.port()); - if (activeHost.equals(this.hostInfo)) + if (activeHost.equals(this.hostInfo) || activeHost.equals(HostInfo.unavailable())) { return Optional.empty(); }