public void ShouldSend100MessagesMultiThreadedWithTransactions() { int count = 100; var stop = Stopwatch.StartNew(); using (var provider = new XmsProducerProvider(true)) { var taskFactory = new TaskFactory(); var tasks = new Task[count]; for (int i = 0; i < count; i++) { tasks[i] = taskFactory.StartNew( () => { using(var scope = new TransactionScope(TransactionScopeOption.Required)) { provider.SendTestMessage(destination); scope.Complete(); } }); } Task.WaitAll(tasks.ToArray()); stop.Stop(); } Console.WriteLine("Sent {0} messages multi-threaded in {1}", count, stop.Elapsed); destination.AssertMessageCount(count); }
public async Task SendAsyncShouldHandleHighVolumeOfMessages(int amount, int maxAsync) { using (var router = new BrokerRouter(new KafkaOptions(IntegrationConfig.IntegrationUri))) using (var producer = new Producer(router, maxAsync) { BatchSize = amount / 2 }) { var tasks = new Task<ProduceResponse[]>[amount]; for (var i = 0; i < amount; i++) { tasks[i] = producer.SendMessageAsync(IntegrationConfig.IntegrationTopic, new[] { new Message(Guid.NewGuid().ToString()) }); } var results = await Task.WhenAll(tasks.ToArray()); //Because of how responses are batched up and sent to servers, we will usually get multiple responses per requested message batch //So this assertion will never pass //Assert.That(results.Count, Is.EqualTo(amount)); Assert.That(results.Any(x => x.Any(y => y.Error != 0)), Is.False, "Should not have received any results as failures."); } }