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
.
For each exception you can configure it with the following parameters.
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();