[英]Is there a way to query the replication factor and retention time for a topic using the Confluent.Kafka .Net client?
The Confluent.Kafka AdminClient allows you to create a topic, specifying the name, number of partitions, replication factor, and retention (and I'm guessing other settings through the configs property). Confluent.Kafka AdminClient 允许您创建一个主题,指定名称、分区数、复制因子和保留(我猜测通过 configs 属性进行其他设置)。 The GetMetadata() call, however, returns a TopicMetadata that only has the name and partition information on it.
然而,GetMetadata() 调用返回一个 TopicMetadata,其中只有名称和分区信息。 Is there a way to retrieve the replication factor and retention time using the.Net client?
有没有办法使用 .Net 客户端检索复制因子和保留时间?
await adminClient.CreateTopicsAsync(new[]
{
new TopicSpecification
{
Name = topicName,
NumPartitions = _connectionSettings.TopicAutoCreatePartitionCount,
ReplicationFactor = _connectionSettings.TopicAutoCreatePartitionCount,
Configs = new Dictionary<string, string> {{"retention.ms", "9999999999999"}}
}
});
To get the retention time you can use DescribeConfigsAsync
:要获取保留时间,您可以使用
DescribeConfigsAsync
:
var results = await adminClient.DescribeConfigsAsync(new[] { new ConfigResource { Name = "topic_name", Type = ResourceType.Topic } });
foreach (var result in results)
{
var retentionConfig = result.Entries.SingleOrDefault(e => e.Key == "retention.ms");
}
But I'm not sure what the correct way to get the replication factor is, since it's not retrieved with DescribedConfigsAsync
.但我不确定获取复制因子的正确方法是什么,因为它不是使用
DescribedConfigsAsync
检索的。 One way I can think of is to use GetMetadata
but it's not a very clean solution:我能想到的一种方法是使用
GetMetadata
但这不是一个非常干净的解决方案:
var meta = adminClient.GetMetadata(TimeSpan.FromSeconds(5));
var topic = meta.Topics.SingleOrDefault(t => t.Topic == "topic_name");
var replicationFactor = topic.Partitions.First().Replicas.Length;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.