I developing some ui tools for kafka. If bootstrap servers are avaialable there is not problem.
But if any bootstrap server is not available i have to handle this.
Also i read this org.apache.kafka.adminclient codes on the github and i saw networkclient has a attribute for this connection status for every node.Networkclient is trying connect to nodes for multiple times. If i can read that connection status, everything gonna wil work as expected.
I can get the status of nodes with below codes but nodes().get() has a timeout and its not best practice for this situation.
@Override
public boolean checkClusterStatus(Cluster cluster, int unit, TimeUnit unitType) throws Exception {
DescribeClusterResult clusterResult = cluster.getAdminClient().describeCluster();
AdminClient client = cluster.getAdminClient();
try {
Collection<Node> nodes = clusterResult.nodes().get(unit,unitType);
//if there is any node details, cluster is available
System.out.println("Cluster is available with nodes - " + nodes);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
cluster.setClusterStatusAvailable(false);
return false;
}
cluster.setClusterStatusAvailable(true);
return true;
}