private static void OnMessageSent(Message message)
 {
     if (!message.Error.HasError)
     {
         MetricsReporter.Produced(1, message.Value.Length);
     }
     else
     {
         MetricsReporter.Error(1);
         Console.WriteLine(message.Error.Reason);
     }
 }
Exemple #2
0
 private async Task LoadAsync(int requestCount, int bodySize, bool publishToKafka)
 {
     if (publishToKafka)
     {
         if (SettingsProvider.GetSettings().MergeMessages)
         {
             var body = GetRandomBody(bodySize * requestCount);
             await kafkaProducer.ProduceAsync(TopicName, Guid.NewGuid(), body);
         }
         else
         {
             var tasks = new List <Task>();
             for (var i = 0; i < requestCount; i++)
             {
                 var body = GetRandomBody(bodySize);
                 random.NextBytes(body);
                 tasks.Add(kafkaProducer.ProduceAsync(TopicName, Guid.NewGuid(), body));
             }
             await Task.WhenAll(tasks.ToArray());
         }
     }
     MetricsReporter.Produced(requestCount, bodySize);
 }