Spring Boot: Kafka-Gesundheitsindikator

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Spring Boot: Kafka-Gesundheitsindikator

by Guest » 12 Jan 2025, 12:02

Ich habe so etwas wie das Folgende, das gut funktioniert, aber ich würde es vorziehen, den Zustand zu überprüfen, ohne eine Nachricht zu senden (nicht nur die Socket-Verbindung zu überprüfen). Ich weiß, dass Kafka so etwas wie KafkaHealthIndicator sofort einsatzbereit hat. Hat jemand Erfahrung oder ein Beispiel dafür?

Code: Select all

   public class KafkaHealthIndicator implements HealthIndicator {
private final Logger log = LoggerFactory.getLogger(KafkaHealthIndicator.class);

private KafkaTemplate kafka;

public KafkaHealthIndicator(KafkaTemplate kafka) {
this.kafka = kafka;
}

@Override
public Health health() {
try {
kafka.send("kafka-health-indicator", "❥").get(100, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
return Health.down(e).build();
}
return Health.up().build();
}
}

Top