We can quickly delete the Kafka topics using Confluent.Kafka library version 1.0.0. But currently, it's in beta release. This library support Kafka admin utilities. Following code helps to clear/delete Kafka topics.
using Confluent.Kafka;
using System;
using System.Collections.Generic;
namespace deleteKafkaTopic
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine($"librdkafka Version: {Library.VersionString} ({Library.Version:X})");
Console.WriteLine($"Debug Contexts: {string.Join(", ", Library.DebugContexts)}");
IEnumerable<string> topicList = new List<string>() { "test-topic4" };
deleteTopics("192.168.64.49:9092", topicList);
}
static void deleteTopics(string brokerList, IEnumerable<string> topicNameList)
{
using (var adminClient = new AdminClient(new AdminClientConfig { BootstrapServers = brokerList }))
{
adminClient.DeleteTopicsAsync(topicNameList, null);
}
}
}
}