public BrokerPartition GetBrokerPartition(KafkaClusterConfig kafkaClusterConfig, string bootstrapServers) { BrokerPartition result; using (var producer = kafkaClusterConfig.BuildProducer(bootstrapServers)) { if (producer == null) { return(null); } var metadata = producer.GetMetadata(); var partitionInfoList = new List <PartitionInfo>(); foreach (var topic in metadata.Topics) { foreach (var partition in topic.Partitions) { var item = new PartitionInfo { Topic = topic.Topic, PartitionId = partition.PartitionId, Leader = partition.Leader, Replicas = partition.Replicas.OrderBy(r => r).ToArray(), ISRs = partition.InSyncReplicas.OrderBy(isr => isr).ToArray() }; partitionInfoList.Add(item); } } result = new BrokerPartition { BrokerId = metadata.OriginatingBrokerId, PartitionInfoList = partitionInfoList }; } return(result); }
private Producer LoadProducer() { return(Config.BuildProducer()); }