From: Kai Moritz Date: Sat, 30 Apr 2022 09:22:41 +0000 (+0200) Subject: HealthIndicator implementiert: Implementierung selbst vergessen :/ X-Git-Tag: endless-stream-consumer-vorlage-DEPRECATED^2~2 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=a330ca24c8a0502e8480bc0aae6179c4e325c724;p=demos%2Fkafka%2Ftraining HealthIndicator implementiert: Implementierung selbst vergessen :/ --- diff --git a/src/main/java/de/juplo/kafka/ApplicationHealthIndicator.java b/src/main/java/de/juplo/kafka/ApplicationHealthIndicator.java new file mode 100644 index 0000000..ab9782c --- /dev/null +++ b/src/main/java/de/juplo/kafka/ApplicationHealthIndicator.java @@ -0,0 +1,32 @@ +package de.juplo.kafka; + +import lombok.RequiredArgsConstructor; +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.actuate.health.HealthIndicator; +import org.springframework.stereotype.Component; + + +@Component +@RequiredArgsConstructor +public class ApplicationHealthIndicator implements HealthIndicator +{ + private final EndlessConsumer consumer; + + + @Override + public Health health() + { + try + { + return consumer + .exitStatus() + .map(Health::down) + .orElse(Health.outOfService()) + .build(); + } + catch (IllegalStateException e) + { + return Health.up().build(); + } + } +}