protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // Cleanup try { MaintenanceService.PurgeQueueAsync(QueueName).GetAwaiter().GetResult(); } catch { } TopologyService.Dispose(); DeliveryService.Dispose(); MaintenanceService.Dispose(); } disposedValue = true; } }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // Cleanup try { RabbitTopologyService.QueueDeleteAsync(TestQueueName1, false, false).GetAwaiter().GetResult(); RabbitTopologyService.QueueDeleteAsync(TestQueueName2, false, false).GetAwaiter().GetResult(); RabbitTopologyService.QueueDeleteAsync(TestQueueName3, false, false).GetAwaiter().GetResult(); RabbitTopologyService.QueueDeleteAsync(TestQueueName4, false, false).GetAwaiter().GetResult(); RabbitTopologyService.ExchangeDeleteAsync(TestExchangeName, false).GetAwaiter().GetResult(); } catch { } RabbitDeliveryService.Dispose(true); RabbitTopologyService.Dispose(true); } disposedValue = true; } }
public static async Task PublishInParallelAsync() { // Configured for performance. var seasoning = new RabbitSeasoning { ThrottleFastBodyLoops = false, ThrowExceptions = false, WriteErrorsToConsole = false, WriteErrorsToILogger = false, BatchBreakOnException = true }; seasoning.PoolSettings.EnableAutoScaling = true; seasoning.PoolSettings.EmptyPoolWaitTime = 0; seasoning.PoolSettings.WriteSleepNoticeToConsole = false; seasoning.PoolSettings.ConnectionPoolCount = 10; seasoning.PoolSettings.ChannelPoolCount = 40; await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Creating RabbitChannelPool and RabbitServices...").ConfigureAwait(false); var sw = Stopwatch.StartNew(); var channelPool = await Factories.CreateRabbitChannelPoolAsync(seasoning).ConfigureAwait(false); var deliveryService = new RabbitDeliveryService(seasoning, channelPool); var topologyService = new RabbitTopologyService(seasoning, channelPool); var maintenanceService = new RabbitMaintenanceService(seasoning, channelPool); sw.Stop(); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Creating RabbitChannelPool and RabbitServices finished. Time: {sw.ElapsedMilliseconds} ms").ConfigureAwait(false); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Creating test data...").ConfigureAwait(false); sw.Reset(); sw.Start(); var queueNames = new List <string> { $"{QueueName}.Scaling_00", $"{QueueName}.Scaling_01", $"{QueueName}.Scaling_02", $"{QueueName}.Scaling_03", $"{QueueName}.Scaling_04", $"{QueueName}.Scaling_05", $"{QueueName}.Scaling_06", $"{QueueName}.Scaling_07", $"{QueueName}.Scaling_08", $"{QueueName}.Scaling_09", }; var envelopes = await CreateEnvelopesAsync(queueNames, MessagesToSend, MessageSizes).ConfigureAwait(false); sw.Stop(); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Creating test data finished. Time: {sw.ElapsedMilliseconds} ms").ConfigureAwait(false); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Creating and/or Purging benchmark queues...").ConfigureAwait(false); sw.Reset(); sw.Start(); foreach (string queueName in queueNames) { await topologyService.QueueDeclareAsync(queueName).ConfigureAwait(false); await maintenanceService.PurgeQueueAsync(queueName).ConfigureAwait(false); } sw.Stop(); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Creating and/or Purging finished. Time: {sw.ElapsedMilliseconds} ms").ConfigureAwait(false); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Publish test starting...").ConfigureAwait(false); sw.Reset(); sw.Start(); await deliveryService.PublishInParallelAsync(envelopes).ConfigureAwait(false); sw.Stop(); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Publish finished. Time: {sw.ElapsedMilliseconds} ms").ConfigureAwait(false); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Publish rate {(MessagesToSend/1.0 / (sw.ElapsedMilliseconds / 1000.0)).ToString("0.###")} msg/s").ConfigureAwait(false); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Purging benchmark queues...").ConfigureAwait(false); sw.Reset(); sw.Start(); foreach (string queueName in queueNames) { await topologyService.QueueDeclareAsync(queueName).ConfigureAwait(false); await maintenanceService.PurgeQueueAsync(queueName).ConfigureAwait(false); } sw.Stop(); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Purging finished. Time: {sw.ElapsedMilliseconds} ms").ConfigureAwait(false); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Shutting down/disposing of services...").ConfigureAwait(false); sw.Reset(); sw.Start(); deliveryService.Dispose(); topologyService.Dispose(); maintenanceService.Dispose(); sw.Stop(); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Shutting down/disposing of services finished. Time: {sw.ElapsedMilliseconds} ms").ConfigureAwait(false); }