Skip to main content
.NETStandard2.0

Package Description

Published
Mar 27, 2023
3y ago
Total Downloads
7.1K
7,074

Install

dotnet add package Rebus.CircuitBreaker --version 0.0.3-alpha01
ProductVersions
.NET Standard
netstandard2.0

README

Rebus.CircuitBreaker

install from nuget

Circuit breaker plugin for Rebus.


It's just

Configure.With(...)
    .(...)
    .Options(o => o.EnableCircuitBreaker(c => c.OpenOn<SomeException>()))
    .Start();

and then the circuit break will open on SomeException.

Settings

For each exception you can configure it with the following parameters.

  • Attempts - The number of attempts with in the the tracking period it takes to Open the circuit breaker
  • TrackingPeriodInSeconds - The period of which errors will be tracked
  • halfOpenPeriodInSeconds - The ammount of time it takes from the last occurance of the Exception for the circuit breaker be but in Half Open Mode
  • ResetIntervalInSeconds - The ammount of time it takes from the last occurance of the Exception for the circuit breaker be but in Closed Mode

Listening for changes

If you want to add custom logic when the state of the circuit breaker changes, you can do this i three easy steps

1. Create your Event Listener

public class MyCustomCircuitBreakerEventListener : IDisposable
{
    CircuitBreakerEvents _circuitBreakerEvents;

    public MyCircuitBreakerEventListener(CircuitBreakerEvents circuitBreakerEvents)
    {
        _circuitBreakerEvents = circuitBreakerEvents;
        _circuitBreakerEvents.CircuitBreakerChanged += CircuitBreakerEvents_CircuitBreakerChanged;
    }

    private void CircuitBreakerEvents_CircuitBreakerChanged(CircuitBreakerState state)
    {
        // Your implementation
    }

    public void Dispose()
    {
        _circuitBreakerEvents = null;
    }
}

2. Create a custom Rebus OptionsConfigurer Extension

public static class MyCustomOptionsConfigurerExtensions
{
    public static void RegisterMyCustomCircuitBreakerEventListener(this OptionsConfigurer self) 
    {
        self.Register(c => new MyCustomCircuitBreakerEventListener(c.Get<CircuitBreakerEvents>()));
    }
}

3. Configure Rebus

Configure.With(...)
    .(...)
    .Options(o => o.EnableCircuitBreaker(c => 
    {
       c.OpenOn<SomeException>()
       c.RegisterMyCustomCircuitBreakerEventListener()
    }))
    .Start();

Changes from Previous Version

No structural changes between v0.0.2 and v0.0.3-alpha01.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 1 target framework; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.