{"id":31900672,"url":"https://github.com/lucastorri/autobreaker","last_synced_at":"2025-10-13T12:26:24.614Z","repository":{"id":57729319,"uuid":"67145966","full_name":"lucastorri/autobreaker","owner":"lucastorri","description":"Automatically wrap Scala classes that return Futures with a Circuit Breaker","archived":false,"fork":false,"pushed_at":"2016-09-18T16:21:42.000Z","size":29,"stargazers_count":9,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-07-23T19:03:08.101Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lucastorri.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-01T15:59:01.000Z","updated_at":"2022-09-24T18:44:51.000Z","dependencies_parsed_at":"2022-09-10T21:51:27.834Z","dependency_job_id":null,"html_url":"https://github.com/lucastorri/autobreaker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lucastorri/autobreaker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucastorri%2Fautobreaker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucastorri%2Fautobreaker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucastorri%2Fautobreaker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucastorri%2Fautobreaker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucastorri","download_url":"https://codeload.github.com/lucastorri/autobreaker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucastorri%2Fautobreaker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279015048,"owners_count":26085643,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-13T12:26:23.523Z","updated_at":"2025-10-13T12:26:24.607Z","avatar_url":"https://github.com/lucastorri.png","language":"Scala","funding_links":[],"categories":["Distributed Systems"],"sub_categories":[],"readme":"# autobreaker\n\n`autobreaker` is a [Scala](http://scala-lang.org/) library that wraps your objects and intercepts all methods returning [`Future`s](http://www.scala-lang.org/api/current/#scala.concurrent.Future) with a [circuit breaker](http://martinfowler.com/bliki/CircuitBreaker.html).\n\nIt is based on [atmos](https://github.com/zmanio/atmos) and [Akka's Circuit Breaker](http://doc.akka.io/docs/akka/current/common/circuitbreaker.html), using [Java's Proxy](https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Proxy.html) to intercept method calls.\n\n\n## Usage\n\n```scala\nimport com.unstablebuild.autobreaker._\n\ntrait MyService {\n  def add(a: Int, b: Int): Future[Int]\n}\n\nclass FailingService extends MyService {\n  override def add(a: Int, b: Int): Future[Int] = Future.failed(new Exception(\"error\"))\n}\n\nval realService: MyService = new FailingService\nval serviceWithCircuitBreaker = AutoBreaker.proxy(realService)\n\n// Make it fail a few times\n(1 to 10).foreach { _ =\u003e serviceWithCircuitBreaker.add(11, 23) }\n\n// Try again and see that the service isn't called\nserviceWithCircuitBreaker.add(11, 23)\n// [warn] e.c.CircuitBreakerProxy - Attempt 1 of operation interrupted: akka.pattern.CircuitBreakerOpenException: Circuit Breaker is open; calls are failing fast\n// akka.pattern.CircuitBreakerOpenException: Circuit Breaker is open; calls are failing fast\n\n```\n\nPlease check the unit tests for more examples.\n\n### Skipping a specific method\n\nYou can prevent a method from being intercept with the `NoCircuitBreaker` annotation. For example:\n\n```scala\nclass AnotherImplementation extends MyService {\n  @NoCircuitBreaker\n  override def add(a: Int, b: Int): Future[Int] = Future.failed(new Exception(\"error\"))\n}\n\n```\n\n\n## Install\n\nTo use it with [SBT](http://www.scala-sbt.org/), add the following to your `build.sbt` file:\n\n```scala\nresolvers += Resolver.sonatypeRepo(\"public\")\n\nlibraryDependencies += \"com.unstablebuild\" %% \"autobreaker\" % \"0.5.6\"\n```\n\n\n## Configuration\n\nThe following settings (and their default values) are available:\n\n```scala\ncase class CircuitBreakerSettings(\n  totalAttempts: TerminationPolicy = 3.attempts,\n  backoffPolicy: BackoffPolicy = LimitedExponentialBackoffPolicy(2.minutes, 1.second),\n  maxFailures: Int = 5,\n  callTimeout: FiniteDuration = 10.seconds,\n  resetTimeout: FiniteDuration = 1.minute,\n  knownError: Throwable =\u003e Boolean = _ =\u003e false\n)\n```\n\nPlease see `atmos` and `akka` documentations for further reference.\n\n`knownError` is used to decide if, given an exception type returned by the method, it should be retried or not, or counted as a failure on the circuit breaker. This allows the usage of custom exceptions to communicate the users about errors that don't affect the used method. For instance, you can decide that an exception communicating validation issues should not be considered as bad as a failure when communicating with a downstream system.\n\n\n## Guice Integration\n\n`autobreaker-guice` allows you to annotate your implementations with `@WithCircuitBreaker` and modify your [Guice](https://github.com/google/guice) module to automatically wrap the generated objects.\n\nIn order to use it, you need to add the following to your dependencies:\n\n```scala\nlibraryDependencies += \"com.unstablebuild\" %% \"autobreaker-guice\" % \"0.5.6\"\n```\n\nAfterwards, it can be used like this:\n\n```scala\n\n@WithCircuitBreaker\nclass DownstreamService extends MyService {\n  override def add(a: Int, b: Int): Future[Int] = ???\n}\n\nclass TestModule extends AbstractModule {\n  override def configure(): Unit = bind(classOf[MyService]).to(classOf[DownstreamService])\n}\n\nval module = new TestModule()\nval injector = Guice.createInjector(AutoBreakerGuice.prepare(module))\nval service = injector.getInstance(classOf[MyService])\n```\n\nAn `ExecutionContext` and `Scheduler` should be available on your bindings.\n\nYou can also use a `AutoBreakerModule` instead of `AbstractModule`, and that will call `AutoBreakerGuice.prepare` for you.\n\n\n### Settings\n\nYou can inject settings in two ways:\n\n1. Bind a `CircuitBreakerSettings`;\n2. Bind a named `CircuitBreakerSettings`.\n\nFor example:\n\n```scala\nbind(classOf[CircuitBreakerSettings])\n          .toInstance(mySettings)\n\nbind(classOf[CircuitBreakerSettings])\n  .annotatedWith(Names.named(\"custom-conf\"))\n  .toInstance(mySettings)\n```\n\nTo use named Settings, you can add the use named to the `WithCircuitBreaker` annotation:\n\n```scala\n@WithCircuitBreaker(name = \"custom-conf\")\nclass CustomNamedFailureTestService(error: Throwable) extends MyService { ... }\n```\n\nIf a Settings instance with the given name is not found, the library will try to use an unnamed one. If it also can't fidn one, it will fall back to `AutoBreaker.defaultSettings`.\n\n\n## Release\n\n```bash\n./sbt test guice/test\n./sbt publishSigned guice/publishSigned\n./sbt sonatypeReleaseAll\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucastorri%2Fautobreaker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucastorri%2Fautobreaker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucastorri%2Fautobreaker/lists"}