Code Monkey home page Code Monkey logo

circuitbreaker.net's Introduction

CircuitBreaker.Net

Build Status NuGet version

Overview

CircuitBreaker.Net is an implementation of the Circuit Breaker pattern for .NET. This pattern can improve the stability and resiliency of your application, especially in SOAP, microservices and distributed environments. The pattern serves two main purposes: to isolate communication with third-party services, so that your application won't be affected by their fails. And to react to third-party services' fails: it could be a pause, throttling, fail-over, default behavior, etc.
You can read about the pattern on MSDN or from Martin Fowler.

Install

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

Example Usage

// Initialize the circuit breaker
var circuitBreaker = new CircuitBreaker(
    TaskScheduler.Default,
    maxFailures: 3,
    invocationTimeout: TimeSpan.FromMilliseconds(100),
    circuitResetTimeout: TimeSpan.FromMilliseconds(10000));

try
{
    // perform a potentially fragile call through the circuit breaker
    circuitBreaker.Execute(externalService.Call);
    // or its async version
    // await circuitBreaker.ExecuteAsync(externalService.CallAsync);
}
catch (CircuitBreakerOpenException)
{
    // the service is unavailable, failover here
}
catch (CircuitBreakerTimeoutException)
{
    // handle timeouts
}
catch (Exception)
{
    // handle other unexpected exceptions
}

Why?

There are not so many of them. I didn't find any that would suit me. Polly seems the most mature from all of them but it has a locking nature and it doesn't provide a way to specify a separate TaskScheduler to execute actions. But that's a crucial aspect when you call a third-party service, because those calls could stuff your "main" TaskScheduler. Actually none of those libraries support injection of a TaskScheduler. Helpful.CircuitBreaker by RokitSalad isn't thread safe. CircuitBreaker by kylos101 executes actions on the same thread. ManagedCircuitBreaker by AsherW is a fork of Polly with emphasize on IoC containers. The code provided on MSDN isn't production ready and just a piece of code. And so on so forth. So that the yet another library was born. I hope you will find it helpful. ๐Ÿ˜‰

circuitbreaker.net's People

Contributors

alexandrnikitin avatar niklasarbin avatar grzesiek-galezowski avatar mkromkamp avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.