I want to get topics list from Kafka. I'm using kafka-net client but unable to find in documentation about fetching topics list.
Get the list of consumer groups for a topic. Use kafka-consumer-groups.sh to list all consumer groups. Note that the below command will list all the consumer groups for all topics managed by the cluster.
A '-list' command is used to list the number of consumer groups available in the Kafka Cluster. The command is used as: 'kafka-consumer-groups. bat -bootstrap-server localhost:9092 -list'.
You can list all topics using the AdminClient available in Confluent.Kafka package:
using Confluent.Kafka;
using Confluent.Kafka.Admin;
var adminConfig = new AdminClientConfig()
{
BootstrapServers = "SERVER_URL"
};
using (var adminClient = new AdminClientBuilder(adminConfig).Build())
{
var metadata = adminClient.GetMetadata(TimeSpan.FromSeconds(10));
var topicsMetadata = metadata.Topics;
var topicNames = metadata.Topics.Select(a => a.Topic).ToList();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With