HealthIndicator implementiert: Implementierung selbst vergessen :/
authorKai Moritz <kai@juplo.de>
Sat, 30 Apr 2022 09:22:41 +0000 (11:22 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 30 Apr 2022 09:22:41 +0000 (11:22 +0200)
src/main/java/de/juplo/kafka/ApplicationHealthIndicator.java [new file with mode: 0644]

diff --git a/src/main/java/de/juplo/kafka/ApplicationHealthIndicator.java b/src/main/java/de/juplo/kafka/ApplicationHealthIndicator.java
new file mode 100644 (file)
index 0000000..ab9782c
--- /dev/null
@@ -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();
+    }
+  }
+}