代码之家  ›  专栏  ›  技术社区  ›  Abdul Manaf

使用C语言以编程方式清除卡夫卡主题#

  •  0
  • Abdul Manaf  · 技术社区  · 7 年前

    合流的卡夫卡

    我可以像这样使用命令行删除卡夫卡主题

    kafka-topics.bat --zookeeper 192.108.94.79:2181 --delete --topic test-topic3
    

    是否有任何库或方法可用于使用C#语言以编程方式清除卡夫卡主题?

    1 回复  |  直到 7 年前
        1
  •  2
  •   Ygalbel    6 年前

    confluent.kafka AdminClient类是内部的, 所以你必须使用 AdminClientBuilder

    例子:

    AdminClientBuilder builder = new AdminClientBuilder(new AdminClientConfig() { BootstrapServers =""})
    
    builder.Build();
    
        2
  •  1
  •   Abdul Manaf    7 年前

    我们可以使用 合流的卡夫卡

    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);
                }
            }
        }
    }
    
    推荐文章