feat(AuthClient): Konfiguration der Wiederholungsrichtlinie im Falle eines Verbindungsverlustes hinzugefügt.
This commit is contained in:
parent
484cc86a29
commit
7f39cbe24a
@ -17,15 +17,19 @@ public class AuthClient : IAuthClient, IAsyncDisposable
|
|||||||
|
|
||||||
public AuthClient(IOptions<ClientParams> paramsOptions, HubConnectionBuilder connectionBuilder, ILogger<AuthClient>? logger = null)
|
public AuthClient(IOptions<ClientParams> paramsOptions, HubConnectionBuilder connectionBuilder, ILogger<AuthClient>? logger = null)
|
||||||
{
|
{
|
||||||
_connection = connectionBuilder
|
_params = paramsOptions.Value;
|
||||||
.WithUrl(paramsOptions.Value.Url)
|
|
||||||
.Build();
|
var cnnBuilder = connectionBuilder.WithUrl(_params.Url);
|
||||||
|
|
||||||
|
// set RetryPolicy if it exists
|
||||||
|
if (_params.RetryPolicy is not null)
|
||||||
|
cnnBuilder = cnnBuilder.WithAutomaticReconnect(_params.RetryPolicy);
|
||||||
|
|
||||||
|
_connection = cnnBuilder.Build();
|
||||||
|
|
||||||
_connection.On<string, string>(nameof(ReceiveKeyAsync), ReceiveKeyAsync);
|
_connection.On<string, string>(nameof(ReceiveKeyAsync), ReceiveKeyAsync);
|
||||||
|
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
_params = paramsOptions.Value;
|
|
||||||
|
|
||||||
_lazyInitiator = new(async () =>
|
_lazyInitiator = new(async () =>
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,10 +1,39 @@
|
|||||||
namespace DigitalData.Auth.Client;
|
using Microsoft.AspNetCore.SignalR.Client;
|
||||||
|
|
||||||
|
namespace DigitalData.Auth.Client;
|
||||||
|
|
||||||
public class ClientParams
|
public class ClientParams
|
||||||
{
|
{
|
||||||
#pragma warning disable CS8618 // throw exception in DI extension if it not set
|
public string Url { get; set; } = string.Empty;
|
||||||
public string Url { get; set; }
|
|
||||||
#pragma warning restore CS8618
|
private readonly Lazy<IRetryPolicy?> _lazyRetryPolicy;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Controls when the client attempts to reconnect and how many times it does so.
|
||||||
|
/// </summary>
|
||||||
|
public IRetryPolicy? RetryPolicy => _lazyRetryPolicy.Value;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// To simplify the assignment of <seealso cref="RetryPolicy"/>
|
||||||
|
/// </summary>
|
||||||
|
public Func<RetryContext, TimeSpan?>? NextRetryDelay { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// To be able to serilize the simple <seealso cref="RetryPolicy"/>
|
||||||
|
/// </summary>
|
||||||
|
public TimeSpan? RetryDelay { get; set; }
|
||||||
|
|
||||||
public readonly ClientEvents Events = new();
|
public readonly ClientEvents Events = new();
|
||||||
|
|
||||||
|
public ClientParams()
|
||||||
|
{
|
||||||
|
_lazyRetryPolicy = new(() =>
|
||||||
|
{
|
||||||
|
if (RetryDelay is not null)
|
||||||
|
return new RetryPolicy(ctx => RetryDelay);
|
||||||
|
else if(NextRetryDelay is not null)
|
||||||
|
return new RetryPolicy(NextRetryDelay);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
17
DigitalData.Auth.Client/RetryPolicy.cs
Normal file
17
DigitalData.Auth.Client/RetryPolicy.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using Microsoft.AspNetCore.SignalR.Client;
|
||||||
|
|
||||||
|
namespace DigitalData.Auth.Client;
|
||||||
|
|
||||||
|
public class RetryPolicy : IRetryPolicy
|
||||||
|
{
|
||||||
|
private readonly TimeSpan _retryDelay;
|
||||||
|
|
||||||
|
private readonly Func<RetryContext, TimeSpan?> _nextRetryDelay;
|
||||||
|
|
||||||
|
public RetryPolicy(Func<RetryContext, TimeSpan?> nextRetryDelay)
|
||||||
|
{
|
||||||
|
_nextRetryDelay = nextRetryDelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimeSpan? NextRetryDelay(RetryContext retryContext) => _nextRetryDelay(retryContext);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user