Describing topics by name
DescribeTopicsAsync(IEnumerable<string>) looks up named topics without creating them by default.
For a missing name, the result dictionary contains a TopicDescription with
ErrorCode.UnknownTopicOrPartition. Other topics in the same request keep their own results.
using Dekaf;
using Dekaf.Admin;
using Dekaf.Protocol;
await using IAdminClient admin = Kafka.CreateAdminClient()
.WithBootstrapServers("localhost:9092")
.Build();
var descriptions = await admin.DescribeTopicsAsync(["orders", "payments"]);
foreach (var (name, description) in descriptions)
{
switch (description.ErrorCode)
{
case ErrorCode.None:
Console.WriteLine($"{name}: {description.Partitions.Count} partitions");
break;
case ErrorCode.UnknownTopicOrPartition:
Console.WriteLine($"{name}: missing");
break;
case ErrorCode.InvalidTopicException:
Console.WriteLine($"{name}: invalid name");
break;
default:
Console.WriteLine($"{name}: {description.ErrorCode}");
break;
}
}
To opt into auto-creation for one call, pass new DescribeTopicsOptions { AllowAutoTopicCreation = true }.
The broker can create a missing topic when auto.create.topics.enable=true and the principal has
permission. The first response can still report an error while the broker creates the topic.
To opt in for every describe, call WithAllowAutoTopicCreation(true) on AdminClientBuilder.
For an admin client from KafkaClient.CreateAdminClient(), configure the shared root with
KafkaClientBuilder.WithAllowAutoCreateTopics(true). The root setting also applies to producer
and consumer metadata lookups. Per-call options override the client setting. A null
AllowAutoTopicCreation uses the default reported by IAdminClientConfigurationInfo.AllowAutoTopicCreation.
The built-in and in-memory admin clients support per-call options through ITopicDescriptionAdminClient.
Custom admin clients must implement this interface to use the options overload.