Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Sep 23, 2024
1 parent 835e60c commit 1b05f4e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 30 deletions.
28 changes: 16 additions & 12 deletions samples/Sample/appsettings.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
49 changes: 31 additions & 18 deletions src/Shiny.Mediator.Resilience/ResilientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TimeoutRejectedException>()
};
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);
// }
});
}
}
Expand All @@ -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; }
}
public int DelayMilliseconds { get; init; } = 3000;
}

// public class CircuitBreakerConfig
// {
//
// }

0 comments on commit 1b05f4e

Please sign in to comment.