Skip to content

Commit

Permalink
Added a delay for the MessageHost restart (#218)
Browse files Browse the repository at this point in the history
* Added 10 seconds delay for the MessageHost restart

* Configurable restart duration
  • Loading branch information
fraliv13 authored May 18, 2022
1 parent 3292351 commit afd0ef1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Messaging/NBB.Messaging.Host/Internal/MessagingHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/Messaging/NBB.Messaging.Host/MessagingHostOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public async Task Shoud_retry_start_failure()
public async Task Shoud_restart_on_transport_error()
{
//Arrange
var hostOptions = Mock.Of<IOptions<MessagingHostOptions>>(x => x.Value == new MessagingHostOptions { TransportErrorStrategy = TransportErrorStrategy.Retry });
var hostOptions = Mock.Of<IOptions<MessagingHostOptions>>(x => x.Value ==
new MessagingHostOptions { TransportErrorStrategy = TransportErrorStrategy.Retry, RestartDelaySeconds = 0 });
var configurator = new DelegateMessagingHostStartup(config =>
config.AddSubscriberServices(s => s.FromTopic("TestTopic")).WithDefaultOptions().UsePipeline(p => { }));

Expand All @@ -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<Func<MessagingEnvelope<object>, Task>>(),
Expand Down

0 comments on commit afd0ef1

Please sign in to comment.