All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.jeqo.dropwizard.kafka.KafkaClientHealthCheck Maven / Gradle / Ivy

There is a newer version: 0.0.6
Show newest version
package io.github.jeqo.dropwizard.kafka;

import com.codahale.metrics.health.HealthCheck;
import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.clients.admin.DescribeClusterResult;

/**
 *
 */
public class KafkaClientHealthCheck extends HealthCheck {
  private final AdminClient adminClient;

  public KafkaClientHealthCheck(AdminClient adminClient) {
    this.adminClient = adminClient;
  }

  @Override
  protected Result check() throws Exception {
    try {
      DescribeClusterResult response = adminClient.describeCluster();
      final boolean nodesNotEmpty = !response.nodes().get().isEmpty();
      final boolean clusterIdAvailable = response.clusterId() != null;
      if (clusterIdAvailable && nodesNotEmpty) {
        return Result.healthy();
      } else {
        return Result.unhealthy("Error connecting to Kafka Cluster");
      }
    } catch (Exception e) {
      return Result.unhealthy("Error connecting to Kafka Cluster", e);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy