public void Init(MQPairConfig config) { if (config == null) { return; } StopListeners(); QueueServerListeners.Clear(); Config = config; Name = Config.Name; OnInit(); Core.Status.Attach(collection => { Core.Status.AttachChild(Counters, this); if (QueueServerListeners?.Any() != true) { return; } foreach (var listener in QueueServerListeners) { Core.Status.AttachChild(listener, this); } }); }
public void Init(MQPairConfig config, bool sendOnly) { if (config is null) { return; } Config = config; SendOnly = sendOnly; Name = Config.Name; Counters = new MQClientCounters(Name, Config.IgnoreClientCounters); SenderSerializer = SerializerManager.GetByMimeType(Config.RequestOptions?.SerializerMimeType); if (SenderSerializer != null && Config.RequestOptions?.CompressorEncodingType.IsNotNullOrEmpty() == true) { SenderSerializer.Compressor = CompressorManager.GetByEncodingType(Config.RequestOptions?.CompressorEncodingType); } ReceiverSerializer = SerializerManager.GetByMimeType(Config.ResponseOptions?.SerializerMimeType); if (ReceiverSerializer != null && Config.ResponseOptions?.CompressorEncodingType.IsNotNullOrEmpty() == true) { ReceiverSerializer.Compressor = CompressorManager.GetByEncodingType(Config.ResponseOptions?.CompressorEncodingType); } OnInit(); }
private static void Init() { if (_init) { return; } _init = true; var queueSettings = Core.GetSettings <QueueConfigurationSettings>(); if (string.IsNullOrEmpty(queueSettings.ConfigFile)) { Core.Log.Warning("The queues configuration file wasn't setted."); return; } queueSettings.ServerName = queueSettings.ServerName ?? Core.ApplicationName; var queuesConfigFile = queueSettings.ConfigFile; queuesConfigFile = queuesConfigFile?.Replace("{EnvironmentName}", Core.EnvironmentName); queuesConfigFile = queuesConfigFile?.Replace("{MachineName}", Core.MachineName); queuesConfigFile = queuesConfigFile?.Replace("{ApplicationName}", Core.ApplicationName); queuesConfigFile = queuesConfigFile?.Replace("{InstanceId}", Core.InstanceIdString); queuesConfigFile = Factory.ResolveLowLowFilePath(queuesConfigFile); Core.Log.InfoBasic("Loading queues configuration: {0}", queuesConfigFile); try { var value = queuesConfigFile.ReadTextFromFile(); value = Core.ReplaceSettingsTemplate(value); value = Core.ReplaceEnvironmentTemplate(value); var serializer = SerializerManager.GetByFileName <ITextSerializer>(queuesConfigFile); _queues = serializer.DeserializeFromString <MQueuesConfiguration>(value); } catch (Exception ex) { throw new Exception($"The Queues config file: {queuesConfigFile} can't be deserialized.", ex); } if (_queues is null) { Core.Log.Warning("The Queues configuration file is null or empty."); return; } if (_queues.Items?.Contains(queueSettings.ServerName) == true) { _queueServer = _queues.Items[queueSettings.ServerName]; } }
private static void RawTest(MQPairConfig mqConfig) { using (var mqServer = mqConfig.GetRawServer()) { var byteRequest = new byte[] { 0x21, 0x22, 0x23, 0x24, 0x25, 0x30, 0x31, 0x32, 0x33, 0x34 }; var byteResponse = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x10, 0x11, 0x12, 0x13, 0x14 }; mqServer.RequestReceived += (s, e) => { e.Response = byteResponse; return(Task.CompletedTask); }; mqServer.StartListeners(); using (var mqClient = mqConfig.GetRawClient()) { var totalQ = 5000; #region Sync Mode Core.Log.Warning("RAW 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(byteRequest).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("RAW 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, vTuple) => (Task)vTuple.mqClient.SendAndReceiveAsync(vTuple.byteRequest), (mqClient, byteRequest)).ToArray() ); //Parallel.For(0, totalQ, i => //{ // var response = mqClient.SendAndReceiveAsync(byteRequest).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 } } }
/// <summary> /// Business message processor /// </summary> /// <param name="pairConfig">Queue server config</param> /// <param name="businessCreationFunction">Business item creation function</param> public BusinessMessageProcessorAsync(MQPairConfig pairConfig, Func <IBusinessAsync> businessCreationFunction) { _creationFunction = businessCreationFunction ?? throw new ArgumentNullException(nameof(businessCreationFunction), "The bussines creation function can't be null"); _maxMessagesPerQueue = pairConfig?.RequestOptions.ServerReceiverOptions.MaxSimultaneousMessagesPerQueue ?? throw new ArgumentNullException(nameof(pairConfig), "The MQPairConfig can't be null"); var serverQueues = pairConfig.ServerQueues?.FirstOf( c => c.EnvironmentName?.SplitAndTrim(",").Contains(Core.EnvironmentName) == true && c.MachineName?.SplitAndTrim(",").Contains(Core.MachineName) == true, c => c.EnvironmentName?.SplitAndTrim(",").Contains(Core.EnvironmentName) == true, c => c.MachineName?.SplitAndTrim(",").Contains(Core.MachineName) == true, c => c.EnvironmentName.IsNullOrWhitespace()); _maxMessages = (serverQueues?.RecvQueues?.Count ?? 0) * _maxMessagesPerQueue; BusinessInitialCount = (int)(_maxMessages * InitialBusinessesPercent) + 1; AttachStatus(); }
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 } } }
/// <summary> /// Message Queue Manager /// </summary> public QueueManager(MQPairConfig config) { Config = config ?? throw new ArgumentNullException("The configuration pair must not be null", nameof(config)); Security = Config.Security?.FirstOf( c => c.EnvironmentName?.SplitAndTrim(",").Contains(Core.EnvironmentName) == true && c.MachineName?.SplitAndTrim(",").Contains(Core.MachineName) == true, c => c.EnvironmentName?.SplitAndTrim(",").Contains(Core.EnvironmentName) == true, c => c.MachineName?.SplitAndTrim(",").Contains(Core.MachineName) == true, c => c.EnvironmentName.IsNullOrWhitespace()); _clientQueues = Config.ClientQueues?.FirstOf( c => c.EnvironmentName?.SplitAndTrim(",").Contains(Core.EnvironmentName) == true && c.MachineName?.SplitAndTrim(",").Contains(Core.MachineName) == true, c => c.EnvironmentName?.SplitAndTrim(",").Contains(Core.EnvironmentName) == true, c => c.MachineName?.SplitAndTrim(",").Contains(Core.MachineName) == true, c => c.EnvironmentName.IsNullOrWhitespace()); _serverQueues = Config.ServerQueues?.FirstOf( c => c.EnvironmentName?.SplitAndTrim(",").Contains(Core.EnvironmentName) == true && c.MachineName?.SplitAndTrim(",").Contains(Core.MachineName) == true, c => c.EnvironmentName?.SplitAndTrim(",").Contains(Core.EnvironmentName) == true, c => c.MachineName?.SplitAndTrim(",").Contains(Core.MachineName) == true, c => c.EnvironmentName.IsNullOrWhitespace()); _admin = Config.GetAdmin(); }
public void Init(MQPairConfig config) { if (config == null) { return; } Config = config; Name = Config.Name; SenderSerializer = SerializerManager.GetByMimeType(Config.RequestOptions?.SerializerMimeType); if (SenderSerializer != null && Config.RequestOptions?.CompressorEncodingType.IsNotNullOrEmpty() == true) { SenderSerializer.Compressor = CompressorManager.GetByEncodingType(Config.RequestOptions?.CompressorEncodingType); } ReceiverSerializer = SerializerManager.GetByMimeType(Config.ResponseOptions?.SerializerMimeType); if (ReceiverSerializer != null && Config.ResponseOptions?.CompressorEncodingType.IsNotNullOrEmpty() == true) { ReceiverSerializer.Compressor = CompressorManager.GetByEncodingType(Config.ResponseOptions?.CompressorEncodingType); } OnInit(); }
protected override void OnHandler(ParameterHandlerInfo info) { Core.Log.Warning("Starting Redis Test"); #region Set Config var mqConfig = new MQPairConfig { Name = "QueueTest", Types = new MQObjectTypes { ClientType = typeof(RedisQueueClient), ServerType = typeof(RedisQueueServer) }, RawTypes = new MQObjectTypes { ClientType = typeof(RedisQueueRawClient), ServerType = typeof(RedisQueueRawServer) }, ClientQueues = new List <MQClientQueues> { new MQClientQueues { EnvironmentName = "", MachineName = "", SendQueues = new List <MQConnection> { new MQConnection("localhost", "TEST_RQ", null) }, RecvQueue = new MQConnection("localhost", "TEST_RS", null) } }, ServerQueues = new List <MQServerQueues> { new MQServerQueues { EnvironmentName = "", MachineName = "", RecvQueues = new List <MQConnection> { new MQConnection("localhost", "TEST_RQ", null) } } }, RequestOptions = new MQRequestOptions { SerializerMimeType = SerializerManager.DefaultBinarySerializer.MimeTypes[0], //CompressorEncodingType = "gzip", ClientSenderOptions = new MQClientSenderOptions { Label = "TEST REQUEST", MessageExpirationInSec = 30, MessagePriority = MQMessagePriority.Normal, Recoverable = false }, ServerReceiverOptions = new MQServerReceiverOptions { MaxSimultaneousMessagesPerQueue = 20000, ProcessingWaitOnFinalizeInSec = 10, SleepOnExceptionInSec = 1000 } }, ResponseOptions = new MQResponseOptions { SerializerMimeType = SerializerManager.DefaultBinarySerializer.MimeTypes[0], //CompressorEncodingType = "gzip", ClientReceiverOptions = new MQClientReceiverOptions(60, new KeyValue <string, string>("SingleResponseQueue", "true") ), ServerSenderOptions = new MQServerSenderOptions { Label = "TEST RESPONSE", MessageExpirationInSec = 30, MessagePriority = MQMessagePriority.Normal, Recoverable = false } } }; #endregion JsonTextSerializerExtensions.Serializer.Indent = true; mqConfig.SerializeToXmlFile("redisConfig.xml"); mqConfig.SerializeToJsonFile("redisConfig.json"); var manager = mqConfig.GetQueueManager(); manager.CreateClientQueues(); //Core.DebugMode = true; //Core.Log.MaxLogLevel = Diagnostics.Log.LogLevel.InfoDetail; Core.Log.Warning("Starting with Normal Listener and Client"); NormalTest(mqConfig); mqConfig.ResponseOptions.ClientReceiverOptions.Parameters["SingleResponseQueue"] = "true"; Core.Log.Warning("Starting with RAW Listener and Client"); RawTest(mqConfig); }
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 } } }
protected override void OnHandler(ParameterHandlerInfo info) { Core.Log.Warning("Starting RabbitMQ Test"); #region Set Config var mqConfig = new MQPairConfig { Name = "QueueTest", Types = new MQObjectTypes { ClientType = typeof(RabbitMQueueClient), ServerType = typeof(RabbitMQueueServer), AdminType = typeof(RabbitMQueueAdmin) }, RawTypes = new MQObjectTypes { ClientType = typeof(RabbitMQueueRawClient), ServerType = typeof(RabbitMQueueRawServer), AdminType = typeof(RabbitMQueueAdmin) }, ClientQueues = new List <MQClientQueues> { new MQClientQueues { EnvironmentName = "", MachineName = "", SendQueues = new List <MQConnection> { new MQConnection("amqp://*****:*****@127.0.0.1:5672/", "TEST_RQ", null) }, RecvQueue = new MQConnection("amqp://*****:*****@127.0.0.1:5672/", "TEST_RS", null) } }, ServerQueues = new List <MQServerQueues> { new MQServerQueues { EnvironmentName = "", MachineName = "", RecvQueues = new List <MQConnection> { new MQConnection("amqp://*****:*****@127.0.0.1:5672/", "TEST_RQ", null) } } }, RequestOptions = new MQRequestOptions { SerializerMimeType = SerializerManager.DefaultBinarySerializer.MimeTypes[0], //CompressorEncodingType = "gzip", ClientSenderOptions = new MQClientSenderOptions { Label = "TEST REQUEST", MessageExpirationInSec = 30, MessagePriority = MQMessagePriority.Normal, Recoverable = false }, ServerReceiverOptions = new MQServerReceiverOptions { MaxSimultaneousMessagesPerQueue = 2000, ProcessingWaitOnFinalizeInSec = 10, SleepOnExceptionInSec = 1000 } }, ResponseOptions = new MQResponseOptions { SerializerMimeType = SerializerManager.DefaultBinarySerializer.MimeTypes[0], //CompressorEncodingType = "gzip", ClientReceiverOptions = new MQClientReceiverOptions(60, new KeyValue <string, string>("SingleResponseQueue", "true") ), ServerSenderOptions = new MQServerSenderOptions { Label = "TEST RESPONSE", MessageExpirationInSec = 30, MessagePriority = MQMessagePriority.Normal, Recoverable = false } } }; #endregion var manager = mqConfig.GetQueueManager(); manager.CreateClientQueues(); Core.Log.Warning("Starting with RAW Listener and Client"); RawTest(mqConfig); }