GithubHelp home page GithubHelp logo

isabella232 / scala-circuit-breaker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hootsuite/scala-circuit-breaker

0.0 0.0 0.0 40 KB

A circuit breaker for Scala applications and services

License: Other

Scala 100.00%

scala-circuit-breaker's Introduction

Circuit Breaker

What is a Circuit Breaker?

A circuit breaker monitors the number of failed requests and decides to delay sending further requests based on configurable threshold. Read more about circuit breakers. Failure threshold, delay time, failure criteria, and event listeners are configurable in config file and code.

Our solution has been powering Scala services in production. It's battle tested and proven.

Quick start guide

Installation

build.sbt

resolvers += Resolver.jcenterRepo // Adds Bintray to resolvers
libraryDependencies ++= Seq("com.hootsuite" %% "scala-circuit-breaker" % "1.x.x")

Usage

Use CircuitBreakerBuilder to initialize circuit breaker:

Configure circuit breaker in reference.conf

circuit-breaker {
  fail-limit = 5 # maximum number of consecutive failures before the circuit breaker is tripped (opened)
  retry-delay = 10 seconds # duration until an open/broken circuit breaker lets a call through to verify whether or not it should be reset
}

Optionally, define the following:

  • a partial function that determines what should be considered as failures

  • a partial function that determines what exceptions that should NOT be considered as failures

  • listeners that will be notified when the circuit breaker changes state (open <--> closed)

  • listeners that will be notified whenever the circuit breaker handles a method/function call

Example

def circuitBreakerBuilder(name: String): CircuitBreakerBuilder = {
    new CircuitBreakerBuilder(
      name = name,
      failLimit = config.getInt("circuit-breaker.fail-limit"),
      retryDelay = Duration(config.getDuration("circuit-breaker.retry-delay", TimeUnit.SECONDS), TimeUnit.SECONDS))
      .withNonFailureExceptionCases {
        // Ignore 4xx level responses
        case _: BadRequest => true
        case _: Unauthorized => true
        case _: NotFound => true
      }
      .withStateChangeListeners(stateChangeListeners)
      .withInvocationListeners(invocationListeners)
  }

Demo

See scala-circuit-breaker-example

How to contribute

Contribute by submitting a PR and a bug report in GitHub.

Maintainers

Diego Alvarez @d1egoaz

Andres Rama @andres_rama_hs

Steve Song @ssongvan

Tatsuhiro Ujihisa @ujm

Johnny Bufu

scala-circuit-breaker is Open Source and available under the Apache 2 License.

This project took inspiration from Sentries which has a BSD 2-Clause License, our solution includes ability to fine-tune what should be considered as failures. It also has hooks when circuit breaker states change.

scala-circuit-breaker's People

Contributors

andrew-gormley-hs avatar denis-golovan-hs avatar diego-alvarez-hs avatar jriecken avatar ssong-van avatar treppo 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.