public void Does_retry_messages_with_errors_by_RetryCount() { var retryCount = 3; var totalRetries = 1 + retryCount; //in total, inc. first try mqHost = CreateMqHost(retryCount); var reverseCalled = 0; var rot13Called = 0; mqHost.RegisterHandler <Reverse>(x => { reverseCalled++; return(x.GetBody().Value.Reverse()); }); mqHost.RegisterHandler <Rot13>(x => { rot13Called++; return(x.GetBody().Value.ToRot13()); }); mqHost.RegisterHandler <AlwaysThrows>(x => { throw new Exception("Always Throwing! " + x.GetBody().Value); }); mqHost.Start(); Thread.Sleep(3000); var mqClient = mqHost.CreateMessageQueueClient(); mqClient.Publish(new Reverse { Value = "Hello" }); mqClient.Publish(new Reverse { Value = "World" }); mqClient.Publish(new Rot13 { Value = "ServiceStack" }); mqClient.Publish(new AlwaysThrows { Value = "1st" }); Thread.Sleep(3000); Assert.That(mqHost.GetStats().TotalMessagesFailed, Is.EqualTo(1 * totalRetries)); Assert.That(mqHost.GetStats().TotalMessagesProcessed, Is.EqualTo(2 + 1)); mqClient.Publish(new Reverse { Value = "Hello" }); mqClient.Publish(new Reverse { Value = "World" }); mqClient.Publish(new Rot13 { Value = "ServiceStack" }); 5.Times(x => mqClient.Publish(new AlwaysThrows { Value = "#" + x })); Thread.Sleep(10000); Debug.WriteLine(mqHost.GetStatsDescription()); Assert.That(mqHost.GetStats().TotalMessagesFailed, Is.EqualTo((1 + 5) * totalRetries)); Assert.That(mqHost.GetStats().TotalMessagesProcessed, Is.EqualTo(6)); Assert.That(reverseCalled, Is.EqualTo(2 + 2)); Assert.That(rot13Called, Is.EqualTo(1 + 1)); mqHost.Dispose(); }
public void Does_retry_messages_with_errors_by_RetryCount() { var retryCount = 3; var totalRetries = 1 + retryCount; //in total, inc. first try mqHost = CreateMqHost(retryCount); var reverseCalled = 0; var rot13Called = 0; mqHost.RegisterHandler<Reverse>(x => { reverseCalled++; return x.GetBody().Value.Reverse(); }); mqHost.RegisterHandler<Rot13>(x => { rot13Called++; return x.GetBody().Value.ToRot13(); }); mqHost.RegisterHandler<AlwaysThrows>(x => { throw new Exception("Always Throwing! " + x.GetBody().Value); }); mqHost.Start(); Thread.Sleep(3000); var mqClient = mqHost.CreateMessageQueueClient(); mqClient.Publish(new Reverse { Value = "Hello" }); mqClient.Publish(new Reverse { Value = "World" }); mqClient.Publish(new Rot13 { Value = "ServiceStack" }); mqClient.Publish(new AlwaysThrows { Value = "1st" }); Thread.Sleep(3000); Assert.That(mqHost.GetStats().TotalMessagesFailed, Is.EqualTo(1 * totalRetries)); Assert.That(mqHost.GetStats().TotalMessagesProcessed, Is.EqualTo(2 + 1)); mqClient.Publish(new Reverse { Value = "Hello" }); mqClient.Publish(new Reverse { Value = "World" }); mqClient.Publish(new Rot13 { Value = "ServiceStack" }); 5.Times(x => mqClient.Publish(new AlwaysThrows { Value = "#" + x })); Thread.Sleep(10000); Debug.WriteLine(mqHost.GetStatsDescription()); Assert.That(mqHost.GetStats().TotalMessagesFailed, Is.EqualTo((1 + 5) * totalRetries)); Assert.That(mqHost.GetStats().TotalMessagesProcessed, Is.EqualTo(6)); Assert.That(reverseCalled, Is.EqualTo(2 + 2)); Assert.That(rot13Called, Is.EqualTo(1 + 1)); mqHost.Dispose(); }