private static void NormalTest(MQPairConfig mqConfig) { using (var mqServer = mqConfig.GetServer()) { mqServer.RequestReceived += (s, e) => { e.Response.Body = "Bienvenido!!!"; return(Task.CompletedTask); }; mqServer.StartListeners(); using (var mqClient = mqConfig.GetClient()) { var totalQ = 5000; #region Sync Mode Core.Log.Warning("Sync Mode Test, using Unique Response Queue"); using (var w = Watch.Create($"Hello World Example in Sync Mode for {totalQ} times")) { for (var i = 0; i < totalQ; i++) { var response = mqClient.SendAndReceiveAsync <string>("Hola mundo").WaitAndResults(); } Core.Log.InfoBasic("Total time: {0}", TimeSpan.FromMilliseconds(w.GlobalElapsedMilliseconds)); Core.Log.InfoBasic("Average time in ms: {0}. Press ENTER To Continue.", (w.GlobalElapsedMilliseconds / totalQ)); } Console.ReadLine(); #endregion #region Parallel Mode Core.Log.Warning("Parallel Mode Test, using Unique Response Queue"); using (var w = Watch.Create($"Hello World Example in Parallel Mode for {totalQ} times")) { Task.WaitAll( Enumerable.Range(0, totalQ).Select((i, mc) => (Task)mc.SendAndReceiveAsync <string>("Hola mundo"), mqClient).ToArray() ); //Parallel.For(0, totalQ, i => //{ // var response = mqClient.SendAndReceiveAsync<string>("Hola mundo").WaitAndResults(); //}); Core.Log.InfoBasic("Total time: {0}", TimeSpan.FromMilliseconds(w.GlobalElapsedMilliseconds)); Core.Log.InfoBasic("Average time in ms: {0}. Press ENTER To Continue.", (w.GlobalElapsedMilliseconds / totalQ)); } Console.ReadLine(); #endregion } } }
private static async Task NormalTest(MQPairConfig mqConfig) { using (var mqServer = mqConfig.GetServer()) { mqServer.RequestReceived += (s, e) => { //Core.Trace.Write("Grupo", e.Request.CorrelationId.ToString(), e.Request.Body); e.Response.Body = new SerializedObject("Bienvenido!!!"); return(Task.CompletedTask); }; mqServer.StartListeners(); using (var mqClient = mqConfig.GetClient()) { var totalQ = 50000; #region Sync Mode Core.Log.Warning("Sync Mode Test, using Unique Response Queue"); using (var w = Watch.Create($"Hello World Example in Sync Mode for {totalQ} times")) { for (var i = 0; i < totalQ; i++) { var response = await mqClient.SendAndReceiveAsync <string>("Hola mundo").ConfigureAwait(false); } Core.Log.InfoBasic("Total time: {0}", TimeSpan.FromMilliseconds(w.GlobalElapsedMilliseconds)); Core.Log.InfoBasic("Average time in ms: {0}. Press ENTER To Continue.", (w.GlobalElapsedMilliseconds / totalQ)); } Console.ReadLine(); #endregion #region Parallel Mode Core.Log.Warning("Parallel Mode Test, using Unique Response Queue"); using (var w = Watch.Create($"Hello World Example in Parallel Mode for {totalQ} times")) { await Task.WhenAll( Enumerable.Range(0, totalQ).Select((i, mqc) => (Task)mqc.SendAndReceiveAsync <string>("Hola mundo"), mqClient).ToArray() ).ConfigureAwait(false); Core.Log.InfoBasic("Total time: {0}", TimeSpan.FromMilliseconds(w.GlobalElapsedMilliseconds)); Core.Log.InfoBasic("Average time in ms: {0}. Press ENTER To Continue.", (w.GlobalElapsedMilliseconds / totalQ)); } Console.ReadLine(); #endregion } } }
private static void NormalTest(MQPairConfig mqConfig) { using (var mqServer = mqConfig.GetServer()) { mqServer.RequestReceived += (s, e) => { //Core.Log.Warning("Waiting..."); //try //{ // await Task.Delay(int.MaxValue, e.ProcessResponseTimeoutCancellationToken); //} //catch { } //Core.Log.Warning("Cancelled."); //Core.Log.InfoBasic("Received"); e.Response.Body = new SerializedObject("Bienvenido!!!"); return(Task.CompletedTask); }; mqServer.StartListeners(); using (var mqClient = mqConfig.GetClient()) { var totalQ = 50000; #region Sync Mode Core.Log.Warning("Sync Mode Test, using Unique Response Queue"); using (var w = Watch.Create($"Hello World Example in Sync Mode for {totalQ} times")) { for (var i = 0; i < totalQ; i++) { var response = mqClient.SendAndReceiveAsync <string>("Hola mundo").WaitAsync(); } Core.Log.InfoBasic("Total time: {0}", TimeSpan.FromMilliseconds(w.GlobalElapsedMilliseconds)); Core.Log.InfoBasic("Average time in ms: {0}. Press ENTER To Continue.", (w.GlobalElapsedMilliseconds / totalQ)); } Console.ReadLine(); #endregion totalQ = 50000; #region Parallel Mode Core.Log.Warning("Parallel Mode Test, using Unique Response Queue"); using (var w = Watch.Create($"Hello World Example in Parallel Mode for {totalQ} times")) { var oldContext = Core.ContextGroupName; Task.WaitAll( Enumerable.Range(0, totalQ).Select((i, mc) => { Core.ContextGroupName = "Message: " + i; return((Task)mc.SendAndReceiveAsync <string>("Hola mundo")); } , mqClient).ToArray()); Core.ContextGroupName = oldContext; //Parallel.For(0, totalQ, i => //{ // var response = mqClient.SendAndReceiveAsync<string>("Hola mundo").WaitAndResults(); //}); Core.Log.InfoBasic("Total time: {0}", TimeSpan.FromMilliseconds(w.GlobalElapsedMilliseconds)); Core.Log.InfoBasic("Average time in ms: {0}. Press ENTER To Continue.", (w.GlobalElapsedMilliseconds / totalQ)); } Console.ReadLine(); #endregion } mqConfig.ResponseOptions.ClientReceiverOptions.Parameters["SingleResponseQueue"] = "false"; using (var mqClient = mqConfig.GetClient()) { var totalQ = 50000; #region Sync Mode Core.Log.Warning("Sync Mode Test, using Multiple Response Queue"); using (var w = Watch.Create($"Hello World Example in Sync Mode for {totalQ} times")) { for (var i = 0; i < totalQ; i++) { var response = mqClient.SendAndReceiveAsync <string>("Hola mundo").WaitAndResults(); } Core.Log.InfoBasic("Total time: {0}", TimeSpan.FromMilliseconds(w.GlobalElapsedMilliseconds)); Core.Log.InfoBasic("Average time in ms: {0}. Press ENTER To Continue.", (w.GlobalElapsedMilliseconds / totalQ)); } Console.ReadLine(); #endregion #region Parallel Mode Core.Log.Warning("Parallel Mode Test, using Multiple Response Queue"); using (var w = Watch.Create($"Hello World Example in Parallel Mode for {totalQ} times")) { Task.WaitAll( Enumerable.Range(0, totalQ).Select((i, mc) => (Task)mc.SendAndReceiveAsync <string>("Hola mundo"), mqClient).ToArray() ); //Parallel.For(0, totalQ, i => //{ // var response = mqClient.SendAndReceiveAsync<string>("Hola mundo").WaitAndResults(); //}); Core.Log.InfoBasic("Total time: {0}", TimeSpan.FromMilliseconds(w.GlobalElapsedMilliseconds)); Core.Log.InfoBasic("Average time in ms: {0}. Press ENTER To Continue.", (w.GlobalElapsedMilliseconds / totalQ)); } Console.ReadLine(); #endregion } } }