diff --git a/samples/Sample/appsettings.json b/samples/Sample/appsettings.json index a0fad77..a64e944 100644 --- a/samples/Sample/appsettings.json +++ b/samples/Sample/appsettings.json @@ -1,53 +1,57 @@ { "Mediator": { + // * fine "Http": { - // * works here - all http contracts will pick up a baseURI - "My.Namespace.Contact": "https://otherlocalhost", + "My.Namespace.Contract": "https://otherlocalhost", "My.Namespace.*" : "https://localhost", "Http.TheActual": "https://localhost:7192" }, + // * fine "PerformanceLogging": { - // * works here "*": { "ErrorThresholdMilliseconds": 5000 } }, + // NO "Offline": { - // * probably a bad idea - block? "Sample.Handlers.OfflineRequestHandler": { "AvailableAcrossSessions": true } }, + // NO "ReplayStream": { "*": { "AvailableAcrossSessions": true } }, + // NO "TimerRefresh": { - // * probably a bad idea - block? "*": { "Interval": 30000 } }, + // NO "Resilience": { - // * probably a bad idea - block? "*": { - "RetryCount": 3, - "RetryDelay": 2000, - "CircuitBreakerCount": 5, - "CircuitBreakerDelay": 5000 + "TimeoutMilliseconds": 5000, + "Retry": { + "MaxAttempts": 3, + "DelayMilliseconds": 2000, + "BackoffType": "Constant", + "UseJitter": true + } } }, + // NO "Cache": { - // * probably a bad idea - block? "*": { "Priority": "High", "AbsoluteExpirationSeconds": 300, "SlidingExpirationSeconds": 60 } }, + // NO "UserErrorNotifications": { - // this works "*": { "*": { "Title": "ERROR", diff --git a/src/Shiny.Mediator.Resilience/ResilientExtensions.cs b/src/Shiny.Mediator.Resilience/ResilientExtensions.cs index d89d880..76bd67c 100644 --- a/src/Shiny.Mediator.Resilience/ResilientExtensions.cs +++ b/src/Shiny.Mediator.Resilience/ResilientExtensions.cs @@ -38,27 +38,29 @@ public static ShinyConfigurator AddResiliencyMiddleware(this ShinyConfigurator c { configurator.Services.AddResiliencePipeline(item.Key.ToLower(), builder => { - if (item.Value.MaxRetries != null) + if (item.Value.TimeoutMilliseconds != null) + builder.AddTimeout(TimeSpan.FromMilliseconds(item.Value.TimeoutMilliseconds.Value)); + + if (item.Value.Retry != null) { + var r = item.Value.Retry; var strategy = new RetryStrategyOptions { - MaxRetryAttempts = item.Value.MaxRetries.Value, - UseJitter = item.Value.UseJitter, + MaxRetryAttempts = r.MaxAttempts, + UseJitter = r.UseJitter, + Delay = TimeSpan.FromMilliseconds(r.DelayMilliseconds), + BackoffType = r.BackoffType, ShouldHandle = new PredicateBuilder().Handle() }; - if (item.Value.RetryDelay != null) - strategy.Delay = TimeSpan.FromSeconds(item.Value.RetryDelay.Value); - - if (item.Value.BackoffType != null) - strategy.BackoffType = item.Value.BackoffType.Value; - builder.AddRetry(strategy); } - - if (item.Value.TimeoutMilliseconds != null) - builder.AddTimeout(TimeSpan.FromMilliseconds(item.Value.TimeoutMilliseconds.Value)); - - // builder.AddCircuitBreaker(new CircuitBreakerStrategyOptions()) + // if (item.Value.CircuitBreaker != null) + // { + // var strategy = new CircuitBreakerStrategyOptions + // { + // }; + // builder.AddCircuitBreaker(strategy); + // } }); } } @@ -70,8 +72,19 @@ public static ShinyConfigurator AddResiliencyMiddleware(this ShinyConfigurator c public class ResilienceConfig { public double? TimeoutMilliseconds { get; init; } - public int? MaxRetries { get; init; } - public int? RetryDelay { get; init; } - public DelayBackoffType? BackoffType { get; init; } + public RetryStrategyConfig? Retry { get; init; } + // public CircuitBreakerConfig? CircuitBreaker { get; init; } +} + +public class RetryStrategyConfig +{ + public int MaxAttempts { get; init; } = 3; + public DelayBackoffType BackoffType { get; init; } = DelayBackoffType.Constant; public bool UseJitter { get; init; } -} \ No newline at end of file + public int DelayMilliseconds { get; init; } = 3000; +} + +// public class CircuitBreakerConfig +// { +// +// } \ No newline at end of file