Inheritance: IQueueClient
コード例 #1
0
		protected void InitializeSubscriptionClient()
		{
			if (!string.IsNullOrWhiteSpace(RedisHost) && RedisPort > 0)
			{
				SubscriptionClient = new QueueClient(RedisHost, RedisPort);
				return;
			}

			SubscriptionClient = new QueueClient();
		}
コード例 #2
0
		protected void InitializeMonitorClient()
		{
			if (!string.IsNullOrWhiteSpace(RedisHost) && RedisPort > 0)
			{
				MonitorClient = new QueueClient(RedisHost, RedisPort);
				return;
			}

			MonitorClient = new QueueClient();
		}
コード例 #3
0
		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);
			}
		}
コード例 #4
0
		public QueueSubscriber()
		{
			Queue = new QueueName(Settings.Default.Queue);
			Client = new QueueClient();
		}
コード例 #5
0
		/// <summary>
		/// Ctor. Creates and consumes a new {RedisQueueClient} instance.
		/// </summary>
		public QueueMonitor()
		{
			Queue = new QueueClient();
		}
コード例 #6
0
		/// <summary>
		/// Ctor. Requires a {RedisQueueClient} instance.
		/// </summary>
		/// <param name="queue"></param>
		public QueueMonitor(QueueClient queue)
		{
			Queue = queue;	
		}
コード例 #7
0
		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);
		}
コード例 #8
0
		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);
		}
コード例 #9
0
		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);
		}