似乎最流行的 .net Kafka 客户端( https://github.com/confluentinc/confluent-kafka-dotnet )缺少设置和创建主题的方法。
打电话时Producer.ProduceAsync()
该主题是自动创建的,但我找不到设置分区、保留策略和其他设置的方法。
我试图在网上找到任何例子,但我发现的只是使用默认值。
也许我可以使用另一个 .net 客户端?
最佳答案
它现在在最新版本的 Confluent.Kafka .Net 客户端库中可用。
见:https://github.com/confluentinc/confluent-kafka-dotnet/blob/b7b04fed82762c67c2841d7481eae59dee3e4e20/examples/AdminClient/Program.cs
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}");
}
}
关于c# - 如何使用 Confluent.Kafka .Net Client 创建 Kafka Topic,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50063406/