Mic*_* D. 6 .net c# apache-kafka confluent-platform
似乎最流行的 .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}");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8993 次 |
| 最近记录: |