Spring Boot: Kafka-GesundheitsindikatorJava

Java-Forum
Guest
 Spring Boot: Kafka-Gesundheitsindikator

Post by Guest »

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();
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post