public StartProcessingAsync ( int threads = -1 ) : void | ||
threads | int | |
return | void |
// global instances that keep controller and windows service alive public void Start(QueueMessageManager manager = null) { if (manager == null) manager = new QueueMessageManagerSql(); LogManager.Current.LogInfo("Start called"); var config = QueueMessageManagerConfiguration.Current; Controller = new QueueController() { ConnectionString = config.ConnectionString, QueueName = config.QueueName, WaitInterval = config.WaitInterval, ThreadCount = config.ControllerThreads }; LogManager.Current.LogInfo("Controller created."); // asynchronously start the SignalR hub SignalR = WebApplication.Start<SignalRStartup>("http://*:8080/"); // *** Spin up n Number of threads to process requests Controller.StartProcessingAsync(); LogManager.Current.LogInfo(String.Format("QueueManager Controller Started with {0} threads.", Controller.ThreadCount)); // Set static instances so that these 'services' stick around GlobalService.Controller = Controller; GlobalService.Service = this; }
public void SingleQueueControllerTest() { var manager = new QueueMessageManagerSql(); // sample - create 3 message for (int i = 0; i < 3; i++) { var item = new QueueMessageItem() { QueueName = "Queue1", Message = "Print Image", Action = "PRINTIMAGE", TextInput = "4334333" // image Id }; // sets appropriate settings for submit on item manager.SubmitRequest(item); // item has to be saved Assert.IsTrue(manager.Save(), manager.ErrorMessage); Console.WriteLine("added " + manager.Item.Id); } Console.WriteLine("Starting... Async Manager Processing"); // create a new Controller to process in the background // on separate threads var controller = new QueueController() { ConnectionString = "QueueMessageManager", ThreadCount = 2, WaitInterval = 200, QueueName = "Queue1" }; Console.WriteLine("Wait: " + controller.WaitInterval); // ExecuteStart Event is where your processing logic goes controller.ExecuteStart += controller_ExecuteStart; // ExecuteFailed and ExecuteComplete let you take actions on completion controller.ExecuteComplete += controller_ExecuteComplete; controller.ExecuteFailed += controller_ExecuteFailed; // actually start the queue controller.StartProcessingAsync(); // For test we have to keep the threads alive // to allow the 3 requests to process Thread.Sleep(2000); // shut down controller.StopProcessing(); Thread.Sleep(200); Console.WriteLine("Stopping... Async Manager Processing"); Assert.IsTrue(true); }