protected void InitializeSubscriptionClient() { if (!string.IsNullOrWhiteSpace(RedisHost) && RedisPort > 0) { SubscriptionClient = new QueueClient(RedisHost, RedisPort); return; } SubscriptionClient = new QueueClient(); }
protected void InitializeMonitorClient() { if (!string.IsNullOrWhiteSpace(RedisHost) && RedisPort > 0) { MonitorClient = new QueueClient(RedisHost, RedisPort); return; } MonitorClient = new QueueClient(); }
public void Stop() { try { Client.Dispose(); Client = new QueueClient(); _log.Info("Stopped subscriber thread."); _log.DebugFormat("Thread Identifier: {0}", _thread.Name); } catch (Exception exception) { _log.Error("Failed to stop subscriber thread.", exception); } }
public QueueSubscriber() { Queue = new QueueName(Settings.Default.Queue); Client = new QueueClient(); }
/// <summary> /// Ctor. Creates and consumes a new {RedisQueueClient} instance. /// </summary> public QueueMonitor() { Queue = new QueueClient(); }
/// <summary> /// Ctor. Requires a {RedisQueueClient} instance. /// </summary> /// <param name="queue"></param> public QueueMonitor(QueueClient queue) { Queue = queue; }
public void TestMonitorCanRecoverFromRedisOutage() { var task = new TaskMessage { Parameters = "blah", Queue = "TestQueue" }; var task2 = new TaskMessage { Parameters = "blah", Queue = "TestQueue" }; var performerMock = new Mock<Performer>(); performerMock.SetupGet(x => x.Status).Returns(new PerformResult { Data = string.Empty, Outcome = Outcome.Success, Reason = string.Empty }); performerMock.Setup(x => x.Perform(task.Parameters)); performerMock.Setup(x => x.Perform(task2.Parameters)); var monitor = new RedisMonitor(); monitor.Performer = performerMock.Object; monitor.Start(); Assert.IsTrue(monitor.Running); using (var client = new QueueClient()) client.Enqueue(task); Thread.Sleep(1500); RedisServer.Kill(); Thread.Sleep(100); RedisServer.Start(); Thread.Sleep(2000); using (var client = new QueueClient()) client.Enqueue(task2); Thread.Sleep(10000); monitor.Stop(); Assert.IsFalse(monitor.Running); }
public void TestMonitorWakesUpOnMessageReceived() { var task = new TaskMessage { Parameters = "blah", Queue = "TestQueue" }; var performerMock = new Mock<Performer>(); performerMock.SetupGet(x => x.Status).Returns(new PerformResult { Data = string.Empty, Outcome = Outcome.Success, Reason = string.Empty }); performerMock.Setup(x => x.Perform(task.Parameters)); var monitor = new RedisMonitor(); monitor.Performer = performerMock.Object; var start = DateTime.Now; monitor.Start(); Assert.IsTrue(monitor.Running); using (var client = new QueueClient()) client.Enqueue(task); monitor.Stop(); Assert.IsFalse(monitor.Running); var stop = DateTime.Now; Assert.Less((stop - start).TotalSeconds, 60); }
public void TestProcessPendingTasksForMultipleTasksMockingPerformerOnly() { #region Prepare Tasks and mock Performer for processing var monitor = new RedisMonitor(); var performerMock = new Mock<Performer>(); using (var client = new QueueClient()) { for (var i = 0; i < 10; i++) { var task = new TaskMessage { Parameters = "Task " + i, Queue = "TestQueue" }; client.Enqueue(task); performerMock.Setup(x => x.Perform(task.Parameters)); } } // ensure all tasks will be successful. performerMock.SetupGet(x => x.Status).Returns(new PerformResult { Data = string.Empty, Outcome = Outcome.Success, Reason = string.Empty }); #endregion monitor.Performer = performerMock.Object; monitor.Start(); Thread.Sleep(2000); monitor.Stop(); for (var i = 0; i < 10; i++) performerMock.Verify(x => x.Perform("Task " + i)); performerMock.VerifyGet(x => x.TaskStorage); performerMock.VerifyGet(x => x.Status); using(var client = new QueueClient()) Assert.AreEqual(client.PendingTasks("TestQueue").Count, 0); }