Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get topics list from Kafka using C#

I want to get topics list from Kafka. I'm using kafka-net client but unable to find in documentation about fetching topics list.

like image 418
Biranchi Panda Avatar asked Jun 13 '15 13:06

Biranchi Panda


People also ask

How do you get a list of consumers connected to a Kafka topic?

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.

How do I view groups in Kafka?

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'.


1 Answers

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();
}
like image 91
educoutinho Avatar answered Oct 13 '22 01:10

educoutinho