Исходный код вики Сброс состояния Kafka
Версия 1.5 от Alexandr Fokin на 2023/07/15 21:29
Последние авторы
author | version | line-number | content |
---|---|---|---|
1 | | |{{code language="c#"}}public static async Task CleanAsync( | ||
2 | KafkaContainer container | ||
3 | ) | ||
4 | { | ||
5 | var connectionString = /* setup connection */; | ||
6 | using var client = new AdminClientBuilder( | ||
7 | new AdminClientConfig() | ||
8 | { | ||
9 | BootstrapServers = connectionString | ||
10 | } | ||
11 | ) | ||
12 | .Build(); | ||
13 | |||
14 | var metadata = client.GetMetadata(TimeSpan.FromSeconds(5)); | ||
15 | var topics = metadata.Topics | ||
16 | .Select(e => e.Topic) | ||
17 | .Where(e => !e.StartsWith("__")) // Не трогаем системные топики | ||
18 | .ToArray(); | ||
19 | |||
20 | if (topics.Length != 0) | ||
21 | { | ||
22 | await client.DeleteTopicsAsync( | ||
23 | topics | ||
24 | ); | ||
25 | } | ||
26 | }{{/code}} | ||
27 | | |[[Testcontainers>>doc:Разработка.Тестирование.Testcontainers.WebHome]], [[Containers pool>>doc:Разработка.Тестирование.Testcontainers.Containers pool.WebHome]] | ||
28 | | |((( | ||
29 | How to get topics list from Kafka using C# | ||
30 | [[https:~~/~~/stackoverflow.com/questions/30819179/how-to-get-topics-list-from-kafka-using-c-sharp>>https://stackoverflow.com/questions/30819179/how-to-get-topics-list-from-kafka-using-c-sharp]] | ||
31 | |||
32 | Is there a way to purge the topic in Kafka? | ||
33 | [[https:~~/~~/stackoverflow.com/questions/16284399/is-there-a-way-to-purge-the-topic-in-kafka>>https://stackoverflow.com/questions/16284399/is-there-a-way-to-purge-the-topic-in-kafka]] | ||
34 | |||
35 | Reset kafka testcontainers without clearing and recreating the testcontainer after every junit test | ||
36 | [[https:~~/~~/stackoverflow.com/questions/72420966/reset-kafka-testcontainers-without-clearing-and-recreating-the-testcontainer-aft/76694930#76694930>>https://stackoverflow.com/questions/72420966/reset-kafka-testcontainers-without-clearing-and-recreating-the-testcontainer-aft/76694930#76694930]] | ||
37 | ))) |