I'm implementing advanced Kafka health-check. Now it's realized "standard" health-check:
@Override
protected void doHealthCheck(Builder builder) {
try (AdminClient adminClient = AdminClient.create(this.kafkaAdmin.getConfig())) {
DescribeClusterResult result = adminClient.describeCluster(this.describeOptions);
String brokerId = result.controller().get().idString();
int replicationFactor = getReplicationFactor(brokerId, adminClient);
int nodes = result.nodes().get().size();
Health h = Option.when(nodes >= replicationFactor, builder::up)
.getOrElse(() ->
builder.down()
.withDetail("clusterId", result.clusterId())
.withDetail("brokerId", brokerId)
.withDetail("nodes", nodes))
.build();
log.info("Current state kafka: {}", h.getStatus(), keyValue(HEALTH, h.getStatus()));
} catch (Exception e) {
Health h = builder.down().build();
log.error("Current state kafka: {}, with error {}", h.getStatus(), e.toString(),
keyValue(HEALTH, h.getStatus()));
}
}
But the goal is to check whether my service is able to read/write from/to certain topic.
I couldn't find appropriate functionality for this in AdminClient and other classes.
And in general it exists?