Class ConnectionSupervisor
Watches one connection or link of a consumer or a producer while its route runs. The connector reports what
happens (, , ); the supervisor keeps the
, the pause before the next attempt (), one log line when the
connection is lost and one when it comes back, the count of recoveries, and the health it gives its endpoint
(). A connector that restores the connection itself runs ; one whose
client restores it only reports.
Thread-safe. The read members (, , ) take no lock and do no
I/O, so health checks read them on every probe.
public sealed class ConnectionSupervisor
Inheritance
Properties
Condition
The health this connection gives its endpoint: null while connected, Warning while
public (EndpointHealthStatus Status, string Reason)? Condition { get; }
DueIn
Time until the next attempt is due; zero when one may run now, and while connected.
public TimeSpan DueIn { get; }
LastFailure
The message of the loss or of the last failed attempt, masked as the endpoint masks its errors.
public string? LastFailure { get; }
State
The state now. A loss reads until an attempt fails, or, with a
public ConnectionState State { get; }
Methods
AttemptAsync<T>(Func<CancellationToken, Task<T>>, Action<T>, CancellationToken)
Runs one connect bounded by . A connect that has not finished by then
public Task<T> AttemptAsync<T>(Func<CancellationToken, Task<T>> connect, Action<T> discardLate, CancellationToken ct)
Failed(Exception)
Reports that an attempt failed: the next one is due after a pause grown by ,
public void Failed(Exception cause)
Lost(Exception)
Reports that the connection is lost. The first report after logs one
public bool Lost(Exception cause)
ReconnectAsync(Func<CancellationToken, Task>, CancellationToken)
The reconnect loop of a connector that restores its connection itself: waits until the next attempt is due, runs
public Task<bool> ReconnectAsync(Func<CancellationToken, Task> reconnect, CancellationToken ct)
Restored()
Reports that the connection is back: logs one information line with the length of the outage, counts the
public void Restored()
Constructors
ConnectionSupervisor(string, ReconnectOptions, ILogger?, TimeProvider?)
Creates a supervisor.