Stability.Net 1.0.4

dotnet add package Stability.Net --version 1.0.4
NuGet\Install-Package Stability.Net -Version 1.0.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Stability.Net" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Stability.Net --version 1.0.4
#r "nuget: Stability.Net, 1.0.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Stability.Net as a Cake Addin
#addin nuget:?package=Stability.Net&version=1.0.4

// Install Stability.Net as a Cake Tool
#tool nuget:?package=Stability.Net&version=1.0.4

Stability

Stability dotnet core library to provide Resiliency pattern for .NET application.

Features!

  • Circuit Breaker
  • Retry Pattern

Installation

It's available via a nuget package
PM> Install-Package Stability.Net

Example : Simple Circuit Breaker

    public async Task Success_with_Close_State() {
        var builder = new CircuitBreakerBuilder();
        var userEntity = new UserEntity();
        var command = builder.AsKey(nameof(userEntity.GetUsers)).WithMaxFailure(3).Build();
        var users = await command.ExecuteAsync(() => userEntity.GetUsers(0), CancellationToken.None);
    }

Example : Circuit Breaker with Fallback

    public async Task Given_Failed_Request_With_Fallback_Should_Execute_Fallback_with_Expected_Result() {
            var builder = CreateBuilder();
            var userEntity = new UserEntity();

            CircuitBreakerCommand command = builder.AsKey(nameof(userEntity.GetUsers)).WithMaxFailure(1).WithResetTimeout(TimeSpan.FromSeconds(1)).Build();
            var users = await command.ExecuteAsync(() => userEntity.GetUsers(10), CancellationToken.None, () => userEntity.GetSuccessResult());
        }

Example : Circuit Breaker with Metrics Collector

// Initialize the MetricsCollector Advance uses with Metrics Collector

      public static class MetricsCollector {
        public static IList<CircuitBreakerMetrics> MetricsStore = new List<CircuitBreakerMetrics>();

        public static void SubscribeMetrics() {
            CircuitBreakerBuilder.Feed.Subscribe(metrics => MetricsStore.Add(metrics));
        }
        public static ICircuitBreakerBuilder CreateCommand(string commandName) {
            var builder = new CircuitBreakerBuilder()
                .AsKey(commandName)
                .WithMaxFailure(3)
                .WithResetTimeout(TimeSpan.FromSeconds(10))
                .WithMaxRetry(3)
                .RetryInterval(new List<TimeSpan>()
                {
                    TimeSpan.FromMilliseconds(100),
                    TimeSpan.FromMilliseconds(500),
                    TimeSpan.FromMilliseconds(1000)
                });

            return builder;
        }
    }

// wrap methods calls
      public async Task<IActionResult> GetCircuitBreaker(string simulate, CancellationToken cancellationToken) {
            var person = new Person();
            var builder = MetricsCollector.CreateCommand("GetEmployee");
            CircuitBreakerCommand command = builder.Build();
            IEnumerable<EmployeeModel> result = null;
            try {
                result = await command.ExecuteAsync(() => person.EmployeeModels(simulate, person), cancellationToken);
            }
            catch (CircuitBreakerOpen e) {
                return NotFound(new { CircuitBreakerBuilder.Metrics, Exception = e });
            }
            catch (Exception) {

            }
            return Ok(new { CommandMetrics = command.Metrics, Data = result });
        }
    // Access Metrics
     public IActionResult GetMetrics() {
            return Ok(MetricsCollector.MetricsStore);
        }
 
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 is compatible.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.4 1,110 12/6/2017
1.0.3 1,009 11/25/2017
1.0.2 1,078 11/20/2017
1.0.1 952 11/19/2017
1.0.0 944 11/18/2017

added Metrics provider
added thread-safe for metrics