You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Retry mecanisme: bijvoorbeeld when (ex is EndpointNotFoundException || ex is CommunicationException)
public class PollyRetryMiddleware
{
private readonly RequestDelegate _next;
private readonly AsyncRetryPolicy _retryPolicy;
public PollyRetryMiddleware(RequestDelegate next)
{
_next = next;
// Define the retry policy: retry 3 times with a 1-second delay between attempts
_retryPolicy = Policy
.Handle<YourSpecificException>() // Replace with the specific exception to handle
.WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(1),
(exception, timeSpan, retryCount, context) =>
{
// Log or handle retries (optional)
Console.WriteLine($"Retry {retryCount} encountered an error: {exception.Message}. Retrying in {timeSpan}.");
});
}
public async Task InvokeAsync(HttpContext context)
{
// Execute the next middleware with the retry policy
await _retryPolicy.ExecuteAsync(async () =>
{
await _next(context);
});
}
}
Have a Controller Action method with:
--> Turn those three cross cutting concerns into 3 different middlewares
(if there isn't yet something like that...)
Others:
The text was updated successfully, but these errors were encountered: