How to create a Kafka Topic using Confluent.Kafka .Net Client
10,827
It is now available in latest release of Confluent.Kafka .Net client library.
using (var adminClient = new AdminClientBuilder(new AdminClientConfig { BootstrapServers = bootstrapServers }).Build())
{
try
{
await adminClient.CreateTopicsAsync(new TopicSpecification[] {
new TopicSpecification { Name = topicName, ReplicationFactor = 1, NumPartitions = 1 } });
}
catch (CreateTopicsException e)
{
Console.WriteLine($"An error occured creating topic {e.Results[0].Topic}: {e.Results[0].Error.Reason}");
}
}
Author by
Michael D.
.Net developer by daily job and Ruby On Rails hobbyist SOreadytohelp
Updated on June 12, 2022Comments
-
Michael D. almost 2 years
It seems like most popular .net client for Kafka (https://github.com/confluentinc/confluent-kafka-dotnet) is missing methods to setup and create Topics. When calling
Producer.ProduceAsync()
the topic is created automatically but I can't find a way to setup partitions, retention policy and other settings.I tried to find any examples online but all I found just use defaults.
Maybe there is another .net client that I can use instead?
-
Michael D. almost 6 yearsThe problem that I am facing is still exists: the topic will be created with all default settings. Simple call to
Producer.ProduceAsync()
also creates a topic if not exists -
OneCricketeer over 2 yearsAnswer needs to be updated with the correct api, or clarify this will use default topic settings