I have a requirement where we have to validate the health check of the system via one single rest point. The idea is to get the number of kafka nodes and their IP's in the cluster running actively via a kafka client.Does kafka provide any API in client to get this info?
Asked
Active
Viewed 507 times
1 Answers
0
Yes, details about all the Kafka nodes in a cluster can be retrieve easily using the describeCluster()
method of the AdminClient.
For example:
Properties adminProps = new Properties();
adminProps.load(new FileInputStream("admin.properties"));
AdminClient adminClient = KafkaAdminClient.create(adminProps);
DescribeClusterResult describeClusterResult = adminClient.describeCluster();
List<Node> nodes = new ArrayList<>(describeClusterResult.nodes().get());
for (Node node : nodes) {
System.out.println("Node id=" + node.id() + " host=" + node.host() + " port=" + node.port());
}

Mickael Maison
- 25,067
- 7
- 71
- 68