diff --git a/src/Messaging/NBB.Messaging.Host/Internal/MessagingHost.cs b/src/Messaging/NBB.Messaging.Host/Internal/MessagingHost.cs index fdf2c2dc..ddf1b694 100644 --- a/src/Messaging/NBB.Messaging.Host/Internal/MessagingHost.cs +++ b/src/Messaging/NBB.Messaging.Host/Internal/MessagingHost.cs @@ -105,8 +105,8 @@ private void OnTransportError(Exception ex) if (strategy == TransportErrorStrategy.Retry) { - _logger.LogInformation($"Restarting host"); - ScheduleRestart(); + _logger.LogInformation($"Restarting host in {_hostOptions.Value.RestartDelaySeconds} seconds"); + ScheduleRestart(TimeSpan.FromSeconds(_hostOptions.Value.RestartDelaySeconds)); } else if (strategy == TransportErrorStrategy.Throw) { diff --git a/src/Messaging/NBB.Messaging.Host/MessagingHostOptions.cs b/src/Messaging/NBB.Messaging.Host/MessagingHostOptions.cs index 37511856..c2f76fb3 100644 --- a/src/Messaging/NBB.Messaging.Host/MessagingHostOptions.cs +++ b/src/Messaging/NBB.Messaging.Host/MessagingHostOptions.cs @@ -7,6 +7,7 @@ public class MessagingHostOptions { public TransportErrorStrategy TransportErrorStrategy { get; set; } = TransportErrorStrategy.Retry; public int StartRetryCount { get; set; } = 10; + public int RestartDelaySeconds { get; set;} = 10; } public enum TransportErrorStrategy diff --git a/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/HostTests.cs b/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/HostTests.cs index be9d11d7..b46f913f 100644 --- a/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/HostTests.cs +++ b/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/HostTests.cs @@ -77,7 +77,8 @@ public async Task Shoud_retry_start_failure() public async Task Shoud_restart_on_transport_error() { //Arrange - var hostOptions = Mock.Of>(x => x.Value == new MessagingHostOptions { TransportErrorStrategy = TransportErrorStrategy.Retry }); + var hostOptions = Mock.Of>(x => x.Value == + new MessagingHostOptions { TransportErrorStrategy = TransportErrorStrategy.Retry, RestartDelaySeconds = 0 }); var configurator = new DelegateMessagingHostStartup(config => config.AddSubscriberServices(s => s.FromTopic("TestTopic")).WithDefaultOptions().UsePipeline(p => { })); @@ -96,7 +97,7 @@ public async Task Shoud_restart_on_transport_error() await messageHost.StartAsync(); Mock.Get(mockedTransportMonitor).Raise(x => x.OnError += _ => { }, new Exception("TransportError")); - await Task.Delay(200); + await Task.Delay(100); //Assert Mock.Get(mockedMessageBus).Verify(x => x.SubscribeAsync(It.IsAny, Task>>(),