in src/NMS.AMQP/Provider/Failover/FailoverProvider.cs [611:658]
public async Task ScheduleReconnect(Func<Task> action)
{
// If no connection recovery required then we have never fully connected to a remote
// so we proceed down the connect with one immediate connection attempt and then follow
// on delayed attempts based on configuration.
if (!recoveryRequired)
{
if (ReconnectAttempts == 0)
{
Tracer.Debug("Initial connect attempt will be performed immediately");
await action().Await();;
}
else if (ReconnectAttempts == 1 && failoverProvider.InitialReconnectDelay > 0)
{
Tracer.Debug($"Delayed initial reconnect attempt will be in {failoverProvider.InitialReconnectDelay} milliseconds");
await Task.Delay(TimeSpan.FromMilliseconds(failoverProvider.InitialReconnectDelay)).Await();;
await action().Await();;
}
else
{
double delay = NextReconnectDelay();
Tracer.Debug($"Next reconnect attempt will be in {delay} milliseconds");
await Task.Delay(TimeSpan.FromMilliseconds(delay)).Await();;
await action().Await();;
}
}
else if (ReconnectAttempts == 0)
{
if (failoverProvider.InitialReconnectDelay > 0)
{
Tracer.Debug($"Delayed initial reconnect attempt will be in {failoverProvider.InitialReconnectDelay} milliseconds");
await Task.Delay(TimeSpan.FromMilliseconds(failoverProvider.InitialReconnectDelay)).Await();
await action().Await();;
}
else
{
Tracer.Debug("Initial Reconnect attempt will be performed immediately");
await action().Await();;
}
}
else
{
double delay = NextReconnectDelay();
Tracer.Debug($"Next reconnect attempt will be in {delay} milliseconds");
await Task.Delay(TimeSpan.FromMilliseconds(delay)).Await();
await action().Await();;
}
}