Refaktorisierung für Tests - Bean-Definition in Config-Klasse verschoben
[demos/kafka/training] / src / main / java / de / juplo / kafka / ApplicationHealthIndicator.java
1 package de.juplo.kafka;
2
3 import lombok.RequiredArgsConstructor;
4 import org.springframework.boot.actuate.health.Health;
5 import org.springframework.boot.actuate.health.HealthIndicator;
6 import org.springframework.stereotype.Component;
7
8
9 @Component
10 @RequiredArgsConstructor
11 public class ApplicationHealthIndicator implements HealthIndicator
12 {
13   private final EndlessConsumer consumer;
14
15
16   @Override
17   public Health health()
18   {
19     try
20     {
21       return consumer
22           .exitStatus()
23           .map(Health::down)
24           .orElse(Health.outOfService())
25           .build();
26     }
27     catch (IllegalStateException e)
28     {
29       return Health.up().build();
30     }
31   }
32 }