private static async Task StartOriginalClient() { var conn = new RabbitMQ.Client.ConnectionFactory() { HostName = TargetHost, VirtualHost = VHost, UserName = _username, Password = _password }.CreateConnection(); var channel = conn.CreateModel(); channel.BasicQos(0, Prefetch, false); channel.ExchangeDeclare("test_ex", "direct", true, false, null); channel.QueueDeclare("queue1", true, false, false, null); channel.QueueBind("queue1", "test_ex", "routing2", null); var prop = channel.CreateBasicProperties(); prop.Type = "type1"; // DeliveryMode = 2, prop.Headers = new Dictionary <string, object> { { "serialization", 0 } }; Console.WriteLine("Started Publishing..."); var watch = Stopwatch.StartNew(); for (int i = 0; i < TotalPublish; i++) { // prop.Headers["serialization"] = i; channel.BasicPublish("test_ex", "routing2", false, prop, MessageContent); } watch.Stop(); Console.WriteLine("Standard BasicPublish stress. Took " + watch.Elapsed.TotalMilliseconds + "ms"); var totalReceived = 0; watch = Stopwatch.StartNew(); channel.BasicConsume("queue1", !WithAcks, new OldStyleConsumer((deliveryTag, prop2, body) => { if (WithAcks) { if (totalReceived % 2 == 0) { channel.BasicAck(deliveryTag, false); } else { channel.BasicNack(deliveryTag, false, false); } } if (++totalReceived == TotalPublish) { watch.Stop(); Console.WriteLine("Consume stress. Took " + watch.Elapsed.TotalMilliseconds + "ms"); totalReceived = 0; } })); await Task.Delay(TimeSpan.FromSeconds(30)); // Thread.CurrentThread.Join(TimeSpan.FromSeconds(30)); }
private static async Task StartOriginalClient() { var conn = new RabbitMQ.Client.ConnectionFactory() { HostName = TargetHost, VirtualHost = VHost, UserName = _username, Password = _password }.CreateConnection(); var channel = conn.CreateModel(); channel.BasicQos(0, Prefetch, false); channel.ExchangeDeclare("test_ex", "direct", true, false, null); channel.QueueDeclare("queue1", true, false, false, null); channel.QueueBind("queue1", "test_ex", "routing2", null); var prop = channel.CreateBasicProperties(); prop.Type = "type1"; // DeliveryMode = 2, prop.Headers = new Dictionary<string, object> { { "serialization", 0 } }; Console.WriteLine("Started Publishing..."); var watch = Stopwatch.StartNew(); for (int i = 0; i < TotalPublish; i++) { // prop.Headers["serialization"] = i; channel.BasicPublish("test_ex", "routing2", false, prop, MessageContent); } watch.Stop(); Console.WriteLine("Standard BasicPublish stress. Took " + watch.Elapsed.TotalMilliseconds + "ms"); var totalReceived = 0; watch = Stopwatch.StartNew(); channel.BasicConsume("queue1", !WithAcks, new OldStyleConsumer((deliveryTag, prop2, body) => { if (WithAcks) { if (totalReceived%2 == 0) channel.BasicAck(deliveryTag, false); else channel.BasicNack(deliveryTag, false, false); } if (++totalReceived == TotalPublish) { watch.Stop(); Console.WriteLine("Consume stress. Took " + watch.Elapsed.TotalMilliseconds + "ms"); totalReceived = 0; } })); await Task.Delay(TimeSpan.FromSeconds(30)); // Thread.CurrentThread.Join(TimeSpan.FromSeconds(30)); }
private static async Task StartOriginalClientRpc() { var conn1 = new RabbitMQ.Client.ConnectionFactory() { HostName = TargetHost, VirtualHost = VHost, UserName = _username, Password = _password }.CreateConnection(); var conn2 = new RabbitMQ.Client.ConnectionFactory() { HostName = TargetHost, VirtualHost = VHost, UserName = _username, Password = _password }.CreateConnection(); var channel = conn1.CreateModel(); channel.BasicQos(0, Prefetch, false); channel.ExchangeDeclare("test_ex", "direct", true, false, null); channel.QueueDeclare("rpc1", true, false, false, null); channel.QueueBind("rpc1", "test_ex", "rpc1", null); Console.WriteLine("Started Rpc server..."); var totalReceived = 0; var watch = Stopwatch.StartNew(); channel.BasicConsume("rpc1", !WithAcks, new OldStyleConsumer((deliveryTag, prop2, body) => { channel.BasicPublish("", prop2.ReplyTo, prop2, body); })); var corr = 0; var channel2 = conn2.CreateModel(); var tempQueue = channel2.QueueDeclare("", false, true, true, null); var ev = new AutoResetEvent(false); // consumes replies channel2.BasicConsume(tempQueue, !WithAcks, new OldStyleConsumer((deliveryTag, prop2, body) => { ev.Set(); })); for (int i = 0; i < TotalPublish; i++) { var propReq = channel2.CreateBasicProperties(); propReq.ReplyTo = tempQueue; propReq.CorrelationId = Interlocked.Increment(ref corr).ToString(); channel2.BasicPublish("test_ex", "rpc1", false, propReq, new byte[4]); ev.WaitOne(); var val = Interlocked.Increment(ref totalReceived); if (val == TotalPublish) { watch.Stop(); Console.WriteLine("Rpc stress. Took " + watch.Elapsed.TotalMilliseconds + "ms - rate of " + (TotalPublish / watch.Elapsed.TotalSeconds) + " message per second"); totalReceived = 0; } } await Task.Delay(TimeSpan.FromSeconds(30)); }