pcsajtai - Trybot 2.4.3-preview-129

Trybot is a transient fault handling framework including such bots as Retry, Timeout, Fallback and Circuit Breaker.

PM> Install-Package Trybot -Version 2.4.3-preview-129 -Source https://www.myget.org/F/pcsajtai/api/v3/index.json

Copy to clipboard

> nuget.exe install Trybot -Version 2.4.3-preview-129 -Source https://www.myget.org/F/pcsajtai/api/v3/index.json

Copy to clipboard

> dotnet add package Trybot --version 2.4.3-preview-129 --source https://www.myget.org/F/pcsajtai/api/v3/index.json

Copy to clipboard
<PackageReference Include="Trybot" Version="2.4.3-preview-129" />
Copy to clipboard
source https://www.myget.org/F/pcsajtai/api/v3/index.json

nuget Trybot  ~> 2.4.3-preview-129
Copy to clipboard

> choco install Trybot --version 2.4.3-preview-129 --source https://www.myget.org/F/pcsajtai/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "pcsajtai" -SourceLocation "https://www.myget.org/F/pcsajtai/api/v2"
Install-Module -Name "Trybot" -RequiredVersion "2.4.3-preview-129" -Repository "pcsajtai" -AllowPreRelease
Copy to clipboard

Browse the sources in this package using Visual Studio or WinDbg by configuring the following symbol server URL: https://www.myget.org/F/pcsajtai/symbols/


trybot Appveyor build status Travis CI build status Tests coverage Sourcelink

Trybot is a transient fault handling framework including such resiliency solutions as Retry, Timeout, Fallback, Rate limit and Circuit Breaker. The framework is extendable with custom, user-defined bots as well. Join the chat at https://gitter.im/z4kn4fein/stashbox Slack

Github (stable) NuGet (stable) MyGet (pre-release) Open Hub
Github release NuGet Version MyGet package OpenHub

Supported platforms

  • .NET 4.5 and above
  • Windows 8/8.1/10
  • Windows Phone Silverlight 8/8.1
  • Windows Phone 8.1
  • Xamarin (Android/iOS/iOS Classic)
  • .NET Standard 1.0/2.0

Bots

  • Retry - Allows to configure auto re-execution of an operation based on exceptions it throws, or on its return value.

  • Timeout - Ensures that the caller won't have to wait indefinitely for an operation to finish by setting a maximum time range within the given operation should be executed.

  • Fallback - Handles faults by executing an alternative operation when the original one is failing, also provides the ability to produce an alternative result value when the original operation is not able to do it.

  • Circuit breaker - Prevents the continuous re-execution of a failing operation by blocking the traffic for a configured amount of time, when the number of failures exceed a given threshold. This usually could give some break to the remote resource to heal itself properly.

  • Rate limit - Controls the rate of the operations by specifying a maximum amount of executions within a given time window.

Usage

During the configuration of a bot policy you can chain different bots to eachother.

policy.Configure(policyConfig => policyConfig
    .CircuitBreaker(circuitBreakerConfig => circuitBreakerConfig
        .DurationOfOpen(TimeSpan.FromSeconds(10))
        .BrakeWhenExceptionOccurs(exception => exception is HttpRequestException),
            strategyConfig => strategyConfig
                .FailureThresholdBeforeOpen(5)
                .SuccessThresholdInHalfOpen(2))

    .Retry(retryConfig => retryConfig
        .WithMaxAttemptCount(5)
        .WhenExceptionOccurs(exception => exception is HttpRequestException)
        .WaitBetweenAttempts((attempt, exception) => 
        {
            if(exception is CircuitOpenException cbException)
                return TimeSpan.FromSeconds(cbException.OpenDuration);

            return TimeSpan.FromSeconds(Math.Pow(2, attempt);
        })))

    .Timeout(timeoutConfig => timeoutConfig
        .After(TimeSpan.FromSeconds(120))));

The handling order of the given operation would be the same as the configuration order from the top to the bottom. That means in the example above that the circuit breaker will try to execute the given operation first, then if it fails the retry bot will start to re-execute it until the timeout bot is not signaling a cancellation.

Then you can execute the configured policy:

  • With cancellation
    var tokenSource = new CancellationTokenSource();
    policy.Execute((context, cancellationToken) => DoSomeCancellableOperation(cancellationToken), tokenSource.Token);
    
  • With a custom correlation id
    var correlationId = Guid.NewGuid();
    policy.Execute((context, cancellationToken) => DoSomeOperationWithCorrelationId(context.CorrelationId), correlationId);
    

    Without setting a custom correlation id, the framework will always generate a unique one for every policy execution.

  • Synchronously
    // Without lambda parameters
    policy.Execute(() => DoSomeOperation());
    
    // Or with lambda parameters
    policy.Execute((context, cancellationToken) => DoSomeOperation());
    
  • Asynchronously
    // Without lambda parameters
    await policy.ExecuteAsync(() => DoSomeAsyncOperation());
    
    // Or with lambda parameters
    await policy.ExecuteAsync((context, cancellationToken) => DoSomeAsyncOperation());
    

You can also create your custom bots as described here.

Extensions

Documentation

  • feature: #2 Feature Request: OnRetrySuccess
  • feature: #3 Feature Request: OnRetryLimitReached
  • .NETFramework 4.5
  • Portable Class Library (.NETFramework 4.5, Windows 8.0, WindowsPhone 8.0, WindowsPhoneApp 8.1)
  • .NETStandard 1.0
    • NETStandard.Library (>= 1.6.1)
  • .NETStandard 2.0
  • .NETFramework 4.5: 4.5.0.0
  • Portable Class Library (.NETFramework 4.5, Windows 8.0, WindowsPhone 8.0, WindowsPhoneApp 8.1): Profile259: 0.0.0.0
  • .NETStandard 1.0: 1.0.0.0
  • .NETStandard 2.0: 2.0.0.0

                        
Assembly Assembly hash Match
/lib/netstandard2.0/trybot.dll 5a97cb4a8fd74e0dbaf9f65bd33ec2caFFFFFFFF
/lib/netstandard1.0/trybot.dll 6213bf978192400aad2e62d1b35a2d36FFFFFFFF
/lib/net45/trybot.dll 7690a78e9c73476b9550d3962c4907bbFFFFFFFF
/lib/portable-net45+win8+wp8+wpa81/trybot.dll 76cc3fbf8ce34d5e9e7fef54a03b1b3aFFFFFFFF

Owners

Authors

Peter Csajtai

Project URL

https://github.com/z4kn4fein/trybot

License

MIT

Tags

Trybot retry timeout fallback circuitbreaker

Info

52 total downloads
1 downloads for version 2.4.3-preview-129
Download (206.74 KB)
Download symbols (206.74 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
2.4.3-preview-129 206.74 KB Mon, 04 Mar 2019 15:55:14 GMT 1
2.4.3-preview-128 206.74 KB Mon, 04 Mar 2019 15:50:26 GMT 1
2.4.3-preview-127 206.72 KB Mon, 04 Mar 2019 15:45:24 GMT 1
2.4.3-preview-126 206.71 KB Thu, 28 Feb 2019 18:23:11 GMT 1
2.4.3-preview-125 203.38 KB Thu, 28 Feb 2019 11:59:33 GMT 1
2.4.3-preview-124 203.25 KB Mon, 25 Feb 2019 23:28:41 GMT 1
2.4.1-preview-123 203.21 KB Mon, 25 Feb 2019 23:24:10 GMT 1
2.4.1-preview-122 197.72 KB Sat, 10 Nov 2018 00:26:19 GMT 1
2.4.1-preview-121 197.72 KB Fri, 09 Nov 2018 18:25:42 GMT 1
2.4.1-preview-120 200.02 KB Fri, 09 Nov 2018 17:41:00 GMT 1
2.4.1-preview-119 200.03 KB Thu, 08 Nov 2018 22:10:36 GMT 1
2.4.1-preview-118 200.03 KB Thu, 08 Nov 2018 21:47:11 GMT 1
2.4.1-preview-116 200.04 KB Thu, 08 Nov 2018 15:26:54 GMT 1
2.4.1-preview-114 196.82 KB Tue, 06 Nov 2018 23:46:28 GMT 1
2.4.1-preview-113 192.93 KB Tue, 06 Nov 2018 17:31:22 GMT 1
2.4.1-preview-112 192.95 KB Mon, 05 Nov 2018 17:13:49 GMT 1
2.4.1-preview-111 186.25 KB Mon, 05 Nov 2018 00:56:53 GMT 1
2.3.6-preview-110 207.46 KB Fri, 26 Oct 2018 16:41:14 GMT 1
2.3.5-preview-109 207.5 KB Fri, 26 Oct 2018 14:32:36 GMT 1
2.3.5-preview-108 207.5 KB Fri, 26 Oct 2018 14:27:39 GMT 1
2.3.5-preview-107 207.5 KB Fri, 26 Oct 2018 14:09:31 GMT 1
2.3.5-preview-106 207.5 KB Fri, 26 Oct 2018 14:03:29 GMT 1
2.3.5-preview-105 210.25 KB Thu, 25 Oct 2018 12:42:10 GMT 1
2.3.5-preview-104 210.24 KB Thu, 25 Oct 2018 11:57:46 GMT 2
2.3.4-preview-99 163.26 KB Mon, 08 Oct 2018 21:32:27 GMT 1
2.3.4-preview-98 163.26 KB Mon, 08 Oct 2018 21:26:12 GMT 1
2.3.4-preview-97 163.26 KB Mon, 08 Oct 2018 21:22:08 GMT 1
2.3.4-preview-96 163.26 KB Mon, 08 Oct 2018 21:18:02 GMT 1
2.3.4-preview-95 163.26 KB Mon, 08 Oct 2018 21:04:20 GMT 1
2.3.4-preview-94 163.26 KB Mon, 08 Oct 2018 20:14:08 GMT 1
2.3.4-preview-103 210.23 KB Wed, 24 Oct 2018 16:23:40 GMT 1
2.3.4-preview-102 210.25 KB Wed, 17 Oct 2018 15:38:26 GMT 1
2.3.4-preview-101 210.25 KB Tue, 16 Oct 2018 10:12:09 GMT 1
2.3.4-preview-100 210.27 KB Mon, 15 Oct 2018 16:43:15 GMT 1
2.3.1-preview-70 150.36 KB Sun, 30 Sep 2018 21:31:27 GMT 1
2.3.1-preview-69 150.39 KB Tue, 25 Sep 2018 16:45:23 GMT 1
2.3.1-preview-68 150.39 KB Tue, 25 Sep 2018 11:57:23 GMT 1
2.3.1-preview-67 150.39 KB Tue, 25 Sep 2018 11:51:48 GMT 1
2.3.1-preview-66 150.39 KB Tue, 25 Sep 2018 10:56:00 GMT 1
2.3.0-preview-65 150.4 KB Mon, 24 Sep 2018 17:51:52 GMT 2
2.3.0-preview-64 150.4 KB Mon, 24 Sep 2018 17:41:20 GMT 1
2.3.0-preview-63 148.74 KB Mon, 24 Sep 2018 14:34:08 GMT 1
2.3.0-preview-59 148.75 KB Mon, 24 Sep 2018 13:03:01 GMT 1
2.3.0-preview-58 148.74 KB Mon, 24 Sep 2018 12:45:25 GMT 1
2.3.0-preview-57 148.74 KB Mon, 24 Sep 2018 12:33:08 GMT 1
2.3.0-preview-56 148.65 KB Mon, 24 Sep 2018 11:02:50 GMT 1
2.3.0-preview-55 148.65 KB Fri, 21 Sep 2018 13:41:00 GMT 1
2.3.0-preview-54 148.65 KB Fri, 21 Sep 2018 13:36:30 GMT 1
2.3.0-preview-53 148.65 KB Fri, 21 Sep 2018 13:29:02 GMT 1
2.3.0-preview-51 148.59 KB Fri, 21 Sep 2018 12:53:24 GMT 1