3

What the title says.

Is there anyway (using Kafka Java API) to get the number of AVAILABLE Kafka brokers in a cluster?

I know that with the command line utility that comes with the Kafka server, this can be done; but I haven't found anything on how to do it using Java API.

Ryuzaki L
  • 37,302
  • 12
  • 68
  • 98

1 Answers1

2

You can get the broker's and cluster information from kafkaAdminClient.describeCluster

Get information about the nodes in the cluster, using the default options. This is a convenience method for #describeCluster(DescribeClusterOptions) with default options. See the overload for more details.

Properties properties = new Properties();
properties.setProperty("bootstrap.servers", "localhost:9092");
properties.setProperty("client.id", "producerAdmin");
properties.setProperty("metadata.max.age.ms", "3000");
kafkaAdminClient = AdminClient.create(properties);

DescribeClusterResult result = kafkaAdminClient.describeCluster()
KafkaFuture<Collection<Node>> nodes = result.nodes();

And you can use host,port methods in Node class to get more information

Ryuzaki L
  • 37,302
  • 12
  • 68
  • 98