本文整理汇总了C#中ISet.Count方法的典型用法代码示例。如果您正苦于以下问题:C# ISet.Count方法的具体用法?C# ISet.Count怎么用?C# ISet.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISet
的用法示例。
在下文中一共展示了ISet.Count方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FetchTopicMetadata
/// <summary>
/// Used by the producer to send a metadata request since it has access to the ProducerConfig
/// </summary>
/// <param name="topics">The topics for which the metadata needs to be fetched</param>
/// <param name="brokers">The brokers in the cluster as configured on the client</param>
/// <param name="producerConfig">The producer's config</param>
/// <param name="correlationId">topic metadata response</param>
/// <returns></returns>
public static TopicMetadataResponse FetchTopicMetadata(
ISet<string> topics, IList<Broker> brokers, ProducerConfig producerConfig, int correlationId)
{
var fetchMetaDataSucceeded = false;
var i = 0;
var topicMetadataRequest = new TopicMetadataRequest(
TopicMetadataRequest.CurrentVersion, correlationId, producerConfig.ClientId, topics.ToList());
TopicMetadataResponse topicMetadataResponse = null;
Exception t = null;
// shuffle the list of brokers before sending metadata requests so that most requests don't get routed to the same broker
var shuffledBrokers = brokers.Shuffle();
while (i < shuffledBrokers.Count() && !fetchMetaDataSucceeded)
{
var producer = ProducerPool.CreateSyncProducer(producerConfig, shuffledBrokers[i]);
Logger.InfoFormat("Fetching metadata from broker {0} with correlation id {1} for {2} topic(s) {3}", shuffledBrokers[i], correlationId, topics.Count, string.Join(",", topics));
try
{
topicMetadataResponse = producer.Send(topicMetadataRequest);
fetchMetaDataSucceeded = true;
}
catch (Exception e)
{
Logger.Warn(string.Format("Fetching topic metadata with correlation id {0} for topic [{1}] from broker [{2}] failed", correlationId, topics, shuffledBrokers[i]), e);
t = e;
}
finally
{
i++;
producer.Dispose();
}
}
if (!fetchMetaDataSucceeded)
{
throw new KafkaException(
string.Format(
"fetching topic metadata for topics [{0}] from broker [{1}] failed", string.Join(",", topics), string.Join(", ", shuffledBrokers)),
t);
}
Logger.DebugFormat("Successfully fetched metadata for {0} topic(s) {1}", topics.Count(), string.Join(",", topics));
return topicMetadataResponse;
}