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();
}
}
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] 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();
}
}
[/code]