{"id":13458727,"url":"https://github.com/resilience4j/resilience4j","last_synced_at":"2025-09-09T20:58:38.035Z","repository":{"id":37359110,"uuid":"36793280","full_name":"resilience4j/resilience4j","owner":"resilience4j","description":"Resilience4j is a fault tolerance library designed for Java8 and functional programming","archived":false,"fork":false,"pushed_at":"2025-05-05T03:33:17.000Z","size":8462,"stargazers_count":10134,"open_issues_count":258,"forks_count":1387,"subscribers_count":213,"default_branch":"master","last_synced_at":"2025-05-07T11:42:03.419Z","etag":null,"topics":["bulkhead","circuitbreaker","metrics","rate-limiter","resilience","retry"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/resilience4j.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":"CONTRIBUTING.adoc","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-06-03T09:21:01.000Z","updated_at":"2025-05-07T09:03:02.000Z","dependencies_parsed_at":"2023-02-13T21:45:57.933Z","dependency_job_id":"3cfa9102-f6fc-4e4f-b893-cee5510f46b6","html_url":"https://github.com/resilience4j/resilience4j","commit_stats":{"total_commits":1418,"total_committers":214,"mean_commits":6.626168224299065,"dds":0.7651622002820875,"last_synced_commit":"8e3e7b864e1150e8b77135cac2566c98b4639446"},"previous_names":["robwin/circuitbreaker-java8","robwin/javaslang-circuitbreaker"],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/resilience4j%2Fresilience4j","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/resilience4j%2Fresilience4j/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/resilience4j%2Fresilience4j/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/resilience4j%2Fresilience4j/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/resilience4j","download_url":"https://codeload.github.com/resilience4j/resilience4j/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254129467,"owners_count":22019628,"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","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":["bulkhead","circuitbreaker","metrics","rate-limiter","resilience","retry"],"created_at":"2024-07-31T09:00:55.913Z","updated_at":"2025-09-09T20:58:38.023Z","avatar_url":"https://github.com/resilience4j.png","language":"Java","funding_links":[],"categories":["Java","Cloud-Computing","Microservices","项目","Capabilities","Projects","Java程序设计","Circuit Breaker \u0026 Bulkheads","中间件","容错组件","others","Networking libraries","三、架构与框架（支撑大型应用）","\u003ca name=\"Java\"\u003e\u003c/a\u003eJava","\u003e 10K ⭐️"],"sub_categories":["分布式应用程序","Resilience","Distributed Applications","资源传输下载","Client-side","6. 分布式与容错"],"readme":"= Fault tolerance library designed for functional programming\n:author: Robert Winkler and Bohdan Storozhuk\n:icons:\n:toc: macro\n:numbered: 1\nifdef::env-github[]\n:tip-caption: :bulb:\n:note-caption: :information_source:\n:important-caption: :heavy_exclamation_mark:\n:caution-caption: :fire:\n:warning-caption: :warning:\nendif::[]\n\nimage:https://github.com/resilience4j/resilience4j/actions/workflows/gradle-build.yml/badge.svg[\"Build Status\"]\nimage:https://img.shields.io/nexus/r/io.github.resilience4j/resilience4j-circuitbreaker?server=https%3A%2F%2Foss.sonatype.org[\"Release\"]\nimage:https://img.shields.io/nexus/s/io.github.resilience4j/resilience4j-circuitbreaker?server=https%3A%2F%2Foss.sonatype.org[\"Snapshot\"]\nimage:http://img.shields.io/badge/license-ASF2-blue.svg[\"Apache License 2\", link=\"http://www.apache.org/licenses/LICENSE-2.0.txt\"]\n\nimage:https://sonarcloud.io/api/project_badges/measure?project=resilience4j_resilience4j\u0026metric=coverage[\"Coverage\", link=\"https://sonarcloud.io/dashboard?id=resilience4j_resilience4j\"]\nimage:https://sonarcloud.io/api/project_badges/measure?project=resilience4j_resilience4j\u0026metric=sqale_rating[\"Maintainability\", link=\"https://sonarcloud.io/dashboard?id=resilience4j_resilience4j\"]\nimage:https://sonarcloud.io/api/project_badges/measure?project=resilience4j_resilience4j\u0026metric=reliability_rating[\"Reliability\", link=\"https://sonarcloud.io/dashboard?id=resilience4j_resilience4j\"]\nimage:https://sonarcloud.io/api/project_badges/measure?project=resilience4j_resilience4j\u0026metric=security_rating[\"Security\", link=\"https://sonarcloud.io/dashboard?id=resilience4j_resilience4j\"]\nimage:https://sonarcloud.io/api/project_badges/measure?project=resilience4j_resilience4j\u0026metric=vulnerabilities[\"Vulnerabilities\", link=\"https://sonarcloud.io/dashboard?id=resilience4j_resilience4j\"]\nimage:https://sonarcloud.io/api/project_badges/measure?project=resilience4j_resilience4j\u0026metric=bugs[\"Bugs\", link=\"https://sonarcloud.io/dashboard?id=resilience4j_resilience4j\"]\n\nimage:https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg[\"SWUbanner\",link=\"https://vshymanskyy.github.io/StandWithUkraine\"]\n\ntoc::[]\n\n== Introduction\n\nResilience4j is a lightweight fault tolerance library designed for functional programming.\nResilience4j provides higher-order functions (decorators) to enhance any functional interface,\nlambda expression or method reference with a Circuit Breaker, Rate Limiter, Retry or Bulkhead.\nYou can stack more than one decorator on any functional interface, lambda expression or method reference.\nThe advantage is that you have the choice to select the decorators you need and nothing else.\n\nResilience4j 3 requires Java 21.\n\n[source,java]\n----\n// Create a CircuitBreaker with default configuration\nCircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults(\"backendService\");\n\n// Create a Retry with default configuration\n// 3 retry attempts and a fixed time interval between retries of 500ms\nRetry retry = Retry.ofDefaults(\"backendService\");\n\n// Create a Bulkhead with default configuration\nBulkhead bulkhead = Bulkhead.ofDefaults(\"backendService\");\n\nSupplier\u003cString\u003e supplier = () -\u003e backendService\n  .doSomething(param1, param2);\n\n// Decorate your call to backendService.doSomething()\n// with a Bulkhead, CircuitBreaker and Retry\n// **note: you will need the resilience4j-all dependency for this\nSupplier\u003cString\u003e decoratedSupplier = Decorators.ofSupplier(supplier)\n  .withCircuitBreaker(circuitBreaker)\n  .withBulkhead(bulkhead)\n  .withRetry(retry)\n  .decorate();\n\n// Execute the decorated supplier and recover from any exception\nString result = Try.ofSupplier(decoratedSupplier)\n  .recover(throwable -\u003e \"Hello from Recovery\").get();\n\n// When you don't want to decorate your lambda expression,\n// but just execute it and protect the call by a CircuitBreaker.\nString result = circuitBreaker\n  .executeSupplier(backendService::doSomething);\n\n// You can also run the supplier asynchronously in a ThreadPoolBulkhead\n ThreadPoolBulkhead threadPoolBulkhead = ThreadPoolBulkhead\n  .ofDefaults(\"backendService\");\n\n// The Scheduler is needed to schedule a timeout on a non-blocking CompletableFuture\nScheduledExecutorService scheduler = Executors.newScheduledThreadPool(3);\nTimeLimiter timeLimiter = TimeLimiter.of(Duration.ofSeconds(1));\n\nCompletableFuture\u003cString\u003e future = Decorators.ofSupplier(supplier)\n    .withThreadPoolBulkhead(threadPoolBulkhead)\n    .withTimeLimiter(timeLimiter, scheduler)\n    .withCircuitBreaker(circuitBreaker)\n    .withFallback(asList(TimeoutException.class, CallNotPermittedException.class, BulkheadFullException.class),\n      throwable -\u003e \"Hello from Recovery\")\n    .get().toCompletableFuture();\n----\n\nNOTE: With Resilience4j you don’t have to go all-in, you can\nhttps://mvnrepository.com/artifact/io.github.resilience4j[*pick what you need*].\n\n==  Documentation\n\nSetup and usage is described in our *https://resilience4j.readme.io/docs[User Guide]*.\n\n- https://github.com/resilience4j-docs-ja/resilience4j-docs-ja[有志による日本語訳(非公式) Japanese translation by volunteers(Unofficial)]\n\n- https://github.com/lmhmhl/Resilience4j-Guides-Chinese[这是Resilience4j的非官方中文文档 Chinese translation by volunteers(Unofficial)]\n\n== Overview\n\nResilience4j provides several core modules:\n\n* resilience4j-circuitbreaker: Circuit breaking\n* resilience4j-ratelimiter: Rate limiting\n* resilience4j-bulkhead: Bulkheading\n* resilience4j-retry: Automatic retrying (sync and async)\n* resilience4j-timelimiter: Timeout handling\n* resilience4j-cache: Result caching\n\nThere are also add-on modules for metrics, Feign, Kotlin, Spring, Ratpack, Vertx, RxJava2 and more.\n\nNOTE: Find out full list of modules in our *https://resilience4j.readme.io/docs#section-modularization[User Guide]*.\n\nTIP: For core modules package or `+Decorators+` builder see *https://mvnrepository.com/artifact/io.github.resilience4j/resilience4j-all[resilience4j-all]*.\n\n== Resilience patterns\n\n[cols=\"\u003c.\u003c*\", options=\"header\"]\n|===\n|name |how does it work? |description |links\n\n|*Retry*\n|repeats failed executions\n|Many faults are transient and may self-correct after a short delay.\n|\u003c\u003ccircuitbreaker-retry-fallback,overview\u003e\u003e,\nhttps://resilience4j.readme.io/docs/retry[documentation],\nhttps://resilience4j.readme.io/docs/getting-started-3#annotations[Spring]\n\n|**Circuit Breaker**\n|temporary blocks possible failures\n|When a system is seriously struggling, failing fast is better than making clients wait.\n|\u003c\u003ccircuitbreaker-retry-fallback,overview\u003e\u003e,\nhttps://resilience4j.readme.io/docs/circuitbreaker[documentation],\nhttps://resilience4j.readme.io/docs/feign[Feign],\nhttps://resilience4j.readme.io/docs/getting-started-3#annotations[Spring]\n\n|**Rate Limiter**\n|limits executions/period\n|Limit the rate of incoming requests.\n|\u003c\u003cratelimiter,overview\u003e\u003e,\nhttps://resilience4j.readme.io/docs/ratelimiter[documentation],\nhttps://resilience4j.readme.io/docs/feign[Feign],\nhttps://resilience4j.readme.io/docs/getting-started-3#annotations[Spring]\n\n|**Time Limiter**\n|limits duration of execution\n|Beyond a certain wait interval, a successful result is unlikely.\n|https://resilience4j.readme.io/docs/timeout[documentation],\nhttps://resilience4j.readme.io/docs/getting-started-3#annotations[Spring]\n\n|**Bulkhead**\n|limits concurrent executions\n|Resources are isolated into pools so that if one fails, the others will continue working.\n|\u003c\u003cbulkhead,overview\u003e\u003e,\nhttps://resilience4j.readme.io/docs/bulkhead[documentation],\nhttps://resilience4j.readme.io/docs/getting-started-3#annotations[Spring]\n\n|**Cache**\n|memorizes a successful result\n|Some proportion of requests may be similar.\n|https://resilience4j.readme.io/docs/cache[documentation]\n\n|**Fallback**\n|provides an alternative result for failures\n|Things will still fail - plan what you will do when that happens.\n|\u003c\u003ccircuitbreaker-retry-fallback,Try::recover\u003e\u003e,\nhttps://resilience4j.readme.io/docs/getting-started-3#section-annotations[Spring],\nhttps://resilience4j.readme.io/docs/feign[Feign]\n\n|===\n\n_Above table is based on https://github.com/App-vNext/Polly#resilience-policies[Polly: resilience policies]._\n\nNOTE: To find more information about resilience patterns check link:#Talks[*Talks*] section.\nFind out more about components in our *https://resilience4j.readme.io/docs/getting-started-2[User Guide]*.\n\n== Spring Boot\n\nSetup and usage in Spring Boot 2 is demonstrated https://github.com/resilience4j/resilience4j-spring-boot2-demo[here].\n\n== Usage examples\n\n[[circuitbreaker-retry-fallback]]\n=== CircuitBreaker, Retry and Fallback\n\nThe following example shows how to decorate a lambda expression (Supplier) with a CircuitBreaker and how to retry the call at most 3 times when an exception occurs.\nYou can configure the wait interval between retries and also configure a custom backoff algorithm.\n\nThe example uses Vavr's Try Monad to recover from an exception and invoke another lambda expression as a fallback, when even all retries have failed.\n\n[source,java]\n----\n// Simulates a Backend Service\npublic interface BackendService {\n    String doSomething();\n}\n\n// Create a CircuitBreaker (use default configuration)\nCircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults(\"backendName\");\n// Create a Retry with at most 3 retries and a fixed time interval between retries of 500ms\nRetry retry = Retry.ofDefaults(\"backendName\");\n\n// Decorate your call to BackendService.doSomething() with a CircuitBreaker\nSupplier\u003cString\u003e decoratedSupplier = CircuitBreaker\n    .decorateSupplier(circuitBreaker, backendService::doSomething);\n\n// Decorate your call with automatic retry\ndecoratedSupplier = Retry\n    .decorateSupplier(retry, decoratedSupplier);\n\n// Use of Vavr's Try to\n// execute the decorated supplier and recover from any exception\nString result = Try.ofSupplier(decoratedSupplier)\n    .recover(throwable -\u003e \"Hello from Recovery\").get();\n\n// When you don't want to decorate your lambda expression,\n// but just execute it and protect the call by a CircuitBreaker.\nString result = circuitBreaker.executeSupplier(backendService::doSomething);\n----\n\n==== CircuitBreaker and RxJava2\n\nThe following example shows how to decorate an Observable by using the custom RxJava operator.\n\n[source,java]\n----\nCircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults(\"testName\");\nObservable.fromCallable(backendService::doSomething)\n    .compose(CircuitBreakerOperator.of(circuitBreaker))\n----\n\nNOTE: Resilience4j also provides RxJava operators for `+RateLimiter+`, `+Bulkhead+`, `+TimeLimiter+` and `+Retry+`.\nFind out more in our *https://resilience4j.readme.io/docs/getting-started-2[User Guide]*.\n\n==== CircuitBreaker and Spring Reactor\n\nThe following example shows how to decorate a Mono by using the custom Reactor operator.\n\n[source,java]\n----\nCircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults(\"testName\");\nMono.fromCallable(backendService::doSomething)\n    .transformDeferred(CircuitBreakerOperator.of(circuitBreaker))\n----\n\nNOTE: Resilience4j also provides Reactor operators for `+RateLimiter+`, `+Bulkhead+`, `+TimeLimiter+` and `+Retry+`.\nFind out more in our *https://resilience4j.readme.io/docs/getting-started-1[User Guide]*.\n\n[[ratelimiter]]\n=== RateLimiter\n\nThe following example shows how to restrict the calling rate of some method to be not higher than 1 request/second.\n\n[source,java]\n----\n// Create a custom RateLimiter configuration\nRateLimiterConfig config = RateLimiterConfig.custom()\n    .timeoutDuration(Duration.ofMillis(100))\n    .limitRefreshPeriod(Duration.ofSeconds(1))\n    .limitForPeriod(1)\n    .build();\n// Create a RateLimiter\nRateLimiter rateLimiter = RateLimiter.of(\"backendName\", config);\n\n// Decorate your call to BackendService.doSomething()\nSupplier\u003cString\u003e restrictedSupplier = RateLimiter\n    .decorateSupplier(rateLimiter, backendService::doSomething);\n\n// First call is successful\nTry\u003cString\u003e firstTry = Try.ofSupplier(restrictedSupplier);\nassertThat(firstTry.isSuccess()).isTrue();\n\n// Second call fails, because the call was not permitted\nTry\u003cString\u003e secondTry = Try.of(restrictedSupplier);\nassertThat(secondTry.isFailure()).isTrue();\nassertThat(secondTry.getCause()).isInstanceOf(RequestNotPermitted.class);\n----\n\n[[bulkhead]]\n=== Bulkhead\nThere are two isolation strategies and bulkhead implementations.\n\n==== SemaphoreBulkhead\nThe following example shows how to decorate a lambda expression with a Bulkhead.\nA Bulkhead can be used to limit the amount of parallel executions.\nThis bulkhead abstraction should work well across a variety of threading and io models.\nIt is based on a semaphore, and unlike Hystrix, does not provide \"shadow\" thread pool option.\n\n[source,java]\n----\n// Create a custom Bulkhead configuration\nBulkheadConfig config = BulkheadConfig.custom()\n    .maxConcurrentCalls(150)\n    .maxWaitDuration(100)\n    .build();\n\nBulkhead bulkhead = Bulkhead.of(\"backendName\", config);\n\nSupplier\u003cString\u003e supplier = Bulkhead\n    .decorateSupplier(bulkhead, backendService::doSomething);\n----\n\n[[threadpoolbulkhead]]\n==== ThreadPoolBulkhead\nThe following example shows how to use a lambda expression with a ThreadPoolBulkhead which uses a bounded queue and a fixed thread pool.\n\n[source,java]\n----\n// Create a custom ThreadPoolBulkhead configuration\nThreadPoolBulkheadConfig config = ThreadPoolBulkheadConfig.custom()\n    .maxThreadPoolSize(10)\n    .coreThreadPoolSize(2)\n    .queueCapacity(20)\n    .build();\n\nThreadPoolBulkhead bulkhead = ThreadPoolBulkhead.of(\"backendName\", config);\n\n// Decorate or execute immediately a lambda expression with a ThreadPoolBulkhead.\nSupplier\u003cCompletionStage\u003cString\u003e\u003e supplier = ThreadPoolBulkhead\n    .decorateSupplier(bulkhead, backendService::doSomething);\n\nCompletionStage\u003cString\u003e execution = bulkhead\n    .executeSupplier(backendService::doSomething);\n----\n\n[[events]]\n== Consume emitted events\n\n`+CircuitBreaker+`, `+RateLimiter+`, `+Cache+`, `+Bulkhead+`, `+TimeLimiter+` and `+Retry+` components emit a stream of events.\nIt can be consumed for logging, assertions and any other purpose.\n\n=== Examples\n\nA `+CircuitBreakerEvent+` can be a state transition, a circuit breaker reset, a successful call, a recorded error or an ignored error.\nAll events contains additional information like event creation time and processing duration of the call.\nIf you want to consume events, you have to register an event consumer.\n\n[source,java]\n----\ncircuitBreaker.getEventPublisher()\n    .onSuccess(event -\u003e logger.info(...))\n    .onError(event -\u003e logger.info(...))\n    .onIgnoredError(event -\u003e logger.info(...))\n    .onReset(event -\u003e logger.info(...))\n    .onStateTransition(event -\u003e logger.info(...));\n// Or if you want to register a consumer listening to all events, you can do:\ncircuitBreaker.getEventPublisher()\n    .onEvent(event -\u003e logger.info(...));\n----\n\nYou can use RxJava or Spring Reactor Adapters to convert the `+EventPublisher+` into a Reactive Stream.\nThe advantage of a Reactive Stream is that you can use RxJava's `+observeOn+` operator to specify a different Scheduler that the CircuitBreaker will use to send notifications to its observers/consumers.\n\n[source,java]\n----\nRxJava2Adapter.toFlowable(circuitBreaker.getEventPublisher())\n    .filter(event -\u003e event.getEventType() == Type.ERROR)\n    .cast(CircuitBreakerOnErrorEvent.class)\n    .subscribe(event -\u003e logger.info(...))\n----\n\nNOTE: You can also consume events from other components.\nFind out more in our *https://resilience4j.readme.io/[User Guide]*.\n\n== Talks\n\n[cols=\"4*\"]\n|===\n\n|0:34\n|https://www.youtube.com/watch?v=kR2sm1zelI4[Battle of the Circuit Breakers: Resilience4J vs Istio]\n|Nicolas Frankel\n|GOTO Berlin\n\n|0:33\n|https://www.youtube.com/watch?v=AwcjOhD91Q0[Battle of the Circuit Breakers: Istio vs. Hystrix/Resilience4J]\n|Nicolas Frankel\n|JFuture\n\n|0:42\n|https://www.youtube.com/watch?v=KosSsZEqS-k\u0026t=157[Resilience patterns in the post-Hystrix world]\n|Tomasz Skowroński\n|Cloud Native Warsaw\n\n|0:52\n|https://www.youtube.com/watch?v=NHVxrLb3jFI[Building Robust and Resilient Apps Using Spring Boot and Resilience4j]\n|David Caron\n|SpringOne\n\n|0:22\n|https://www.youtube.com/watch?v=gvDvOWtPLVY\u0026t=140[Hystrix is dead, now what?]\n|Tomasz Skowroński\n|DevoxxPL\n\n|===\n\n== Companies that use Resilience4j\n\n* *Deutsche Telekom* (In an application with over 400 million requests per day)\n* *AOL* (In an application with low latency requirements)\n* *Netpulse* (In a system with 40+ integrations)\n* *wescale.de* (In a B2B integration platform)\n* *Topia* (In an HR application built with microservices architecture)\n* *Auto Trader Group plc* (The largest Britain digital automotive marketplace)\n* *PlayStation Network* (A platform backend)\n* *TUI InfoTec GmbH* (Backend applications inside of reservation booking workflow streams for accommodations)\n\n== License\n\nCopyright 2020 Robert Winkler, Bohdan Storozhuk, Mahmoud Romeh, Dan Maas and others\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fresilience4j%2Fresilience4j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fresilience4j%2Fresilience4j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fresilience4j%2Fresilience4j/lists"}