Исходный код вики Сброс состояния Kafka
Редактировал(а) Alexandr Fokin 2024/07/01 11:01
Скрыть последних авторов
| author | version | line-number | content |
|---|---|---|---|
| |
1.5 | 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}} | ||
| |
3.1 | 27 | | |[[Testcontainers>>doc:Разработка.Тестирование.TestContainers.WebHome]], [[Containers pool>>doc:Разработка.Тестирование.TestContainers.Containers pool.WebHome]] |
| |
1.5 | 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 | ))) |