有没有办法使用 Confluent.Kafka .Net 客户端查询主题的复制因子和保留时间?

Is there a way to query the replication factor and retention time for a topic using the Confluent.Kafka .Net client?

Confluent.Kafka AdminClient 允许您创建一个主题,指定名称、分区数、复制因子和保留(我猜测通过配置 属性 进行的其他设置)。但是,GetMetadata() 调用 returns 一个只有名称和分区信息的 TopicMetadata。有没有办法使用 .Net 客户端检索复制因子和保留时间?

 await adminClient.CreateTopicsAsync(new[]
                    {
                        new TopicSpecification
                        {
                            Name = topicName,
                            NumPartitions = _connectionSettings.TopicAutoCreatePartitionCount,
                            ReplicationFactor = _connectionSettings.TopicAutoCreatePartitionCount,
                            Configs = new Dictionary<string, string> {{"retention.ms", "9999999999999"}}
                        }
                    });

要获得保留时间,您可以使用 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");
}

但我不确定获取复制因子的正确方法是什么,因为它不是用 DescribedConfigsAsync 检索的。我能想到的一种方法是使用 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;