public void Dispose() { adminClient.DeleteTopicsAsync(new List <string> { Name }).Wait(); adminClient.Dispose(); }
static void deleteTopics(string brokerList, IEnumerable <string> topicNameList) { using (var adminClient = new AdminClient(new AdminClientConfig { BootstrapServers = brokerList })) { adminClient.DeleteTopicsAsync(topicNameList, null); } }
private static void DeleteTopic(IConfigurationRoot config) { var adminClientConfig = new AdminClientConfig { BootstrapServers = config["BootstrapServers"] }; var adminClient = new AdminClient(adminClientConfig); var topic = config["TopicName"]; var metadata = adminClient.GetMetadata(TimeSpan.FromSeconds(10)); if (metadata.Topics.Any(x => x.Topic == topic)) { adminClient.DeleteTopicsAsync(new[] { topic }).Wait(); } }
private static void DeleteTopic() { using (var producer = new Producer <Null, string>(GetConfig())) { using (var adminClient = new AdminClient(producer.Handle)) { try { adminClient.DeleteTopicsAsync(new List <string> { TOPIC }).Wait(); } catch (Exception ex) { } } } }
public static void AdminClient_DeleteTopics(string bootstrapServers, string singlePartitionTopic, string partitionedTopic) { LogToFile("start AdminClient_DeleteTopics"); var topicName1 = Guid.NewGuid().ToString(); var topicName2 = Guid.NewGuid().ToString(); var topicName3 = Guid.NewGuid().ToString(); // test single delete topic. using (var adminClient = new AdminClient(new AdminClientConfig { BootstrapServers = bootstrapServers })) { adminClient.CreateTopicsAsync( new List <TopicSpecification> { new TopicSpecification { Name = topicName1, NumPartitions = 1, ReplicationFactor = 1 } }).Wait(); Thread.Sleep(TimeSpan.FromSeconds(1)); Thread.Sleep(TimeSpan.FromSeconds(2)); // git the topic some time to be created. adminClient.DeleteTopicsAsync(new List <string> { topicName1 }).Wait(); } // test // - delete two topics, one that doesn't exist. // - check that explicitly giving options doesn't obviously not work. using (var adminClient = new AdminClient(new AdminClientConfig { BootstrapServers = bootstrapServers })) { adminClient.CreateTopicsAsync( new List <TopicSpecification> { new TopicSpecification { Name = topicName2, NumPartitions = 1, ReplicationFactor = 1 } }).Wait(); Thread.Sleep(TimeSpan.FromSeconds(1)); Thread.Sleep(TimeSpan.FromSeconds(2)); try { adminClient.DeleteTopicsAsync( new List <string> { topicName2, topicName3 }, new DeleteTopicsOptions { RequestTimeout = TimeSpan.FromSeconds(30) } ).Wait(); } catch (AggregateException ex) { var dte = (DeleteTopicsException)ex.InnerException; Assert.Equal(2, dte.Results.Count); Assert.Single(dte.Results.Where(r => r.Error.IsError)); Assert.Single(dte.Results.Where(r => !r.Error.IsError)); Assert.Equal(topicName2, dte.Results.Where(r => !r.Error.IsError).First().Topic); Assert.Equal(topicName3, dte.Results.Where(r => r.Error.IsError).First().Topic); } } Assert.Equal(0, Library.HandleCount); LogToFile("end AdminClient_DeleteTopics"); }