{"id":18947481,"url":"https://github.com/pepperkit/retry","last_synced_at":"2025-09-07T08:34:15.536Z","repository":{"id":45079964,"uuid":"339149093","full_name":"pepperkit/retry","owner":"pepperkit","description":"This is a free, simple retry library for Java - is pure implementation without any dependency. It helps you transparently retry failed operations.","archived":false,"fork":false,"pushed_at":"2022-01-10T12:03:00.000Z","size":160,"stargazers_count":4,"open_issues_count":8,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-01T22:12:51.797Z","etag":null,"topics":["backoff-algorithm","java","retry","retry-library","retry-pattern","retryit"],"latest_commit_sha":null,"homepage":"","language":"Java","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/pepperkit.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":"2021-02-15T17:09:35.000Z","updated_at":"2024-08-14T06:15:54.000Z","dependencies_parsed_at":"2022-09-11T16:40:49.923Z","dependency_job_id":null,"html_url":"https://github.com/pepperkit/retry","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/pepperkit/retry","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pepperkit%2Fretry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pepperkit%2Fretry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pepperkit%2Fretry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pepperkit%2Fretry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pepperkit","download_url":"https://codeload.github.com/pepperkit/retry/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pepperkit%2Fretry/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274012593,"owners_count":25207277,"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-09-07T02:00:09.463Z","response_time":67,"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":["backoff-algorithm","java","retry","retry-library","retry-pattern","retryit"],"created_at":"2024-11-08T13:10:06.456Z","updated_at":"2025-09-07T08:34:15.495Z","avatar_url":"https://github.com/pepperkit.png","language":"Java","readme":"# retry\n\n[![Build](https://github.com/pepperkit/retry/actions/workflows/gradle.yml/badge.svg)](https://github.com/pepperkit/retry/actions/workflows/gradle.yml)\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=aukhatov_retry\u0026metric=coverage)](https://sonarcloud.io/dashboard?id=aukhatov_retry)\n\nThis is a simple and lightweight retry library for Java. It helps you transparently retry failed operations.\n\n### Dependency\n\n#### Maven\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.github.pepperkit\u003c/groupId\u003e\n    \u003cartifactId\u003eretry\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n#### Gradle\n\n```groovy\nimplementation 'io.github.pepperkit:retry:1.0.0'\n```\n\n### Backoff Functions\nThe backoff function determines how much to wait between the retries.\n\n#### Exponential\nIt waits progressively longer intervals between subsequent retries.\n```text\n3s -\u003e 9s -\u003e 27s -\u003e 81s\n```\n```java\nimport io.github.pepperkit.retry.BackoffFunction;\n\nnew BackoffFunction.Exponential(3);\n```\n\n#### Fixed\nThis is an elementary implementation, just return a constant value.\n```text\n3s -\u003e 3s -\u003e 3s -\u003e 3s\n```\n```java\nimport io.github.pepperkit.retry.BackoffFunction;\n\nnew BackoffFunction.Fixed();\n```\n\n#### Randomized\nThis function returns a random interval value. The algorithm doesn't declare how much the rate of an operation will be reduced. \n```text\n12s -\u003e 4s -\u003e 3s -\u003e 9s\n```\n```java\nimport io.github.pepperkit.retry.BackoffFunction;\n\nnew BackoffFunction.Randomized(5);\n```\n\n#### Custom\nYou can implement your own version of backoff function by the interface.\n```java\n@FunctionalInterface\npublic interface BackoffFunction {\n\n    Duration delay(int attempt, Duration delay);\n}\n```\n\n## Usage\n\n### Methods Definition\n\n- `retry()` - initiates the retry function\n- `backoff(BackoffFunction function)` - a function to compute next delay interval\n- `delay(Duration duration)` - an initial delay interval\n- `maxDelay(Duration duration)` - the maximum delay interval value\n- `handle(Class\u003c? extends Throwable\u003e)` - specifies a type of Exception which has to be handled to retry (if it doesn't specify any exception will be handled by default)\n- `abortIf(Class\u003c? extends Throwable\u003e)` - when the exception has occurred the retryable function will be interrupted\n- `onFailure(Consumer\u003c? super Throwable\u003e)` - specifies a function to handle the exception\n- `run()` - perform an action (function) which can be retried\n- `call()` - compute a result which can be retried\n\n### Exponential Backoff\n\nThe **exponential** backoff algorithm implementation.\nIt uses to **gradually reduce the rate** of the operation if the exception _(or any)_ occurred.\n\n```java\nimport static io.github.pepperkit.retry.Retry.retry;\n\n    retry(3)\n        .backoff(new BackoffFunction.Exponential())\n        .delay(Duration.ofMillis(500))\n        .maxDelay(Duration.ofSeconds(3))\n        .handle(HttpServiceUnavailable.class)\n        .run(()-\u003e{\n            webClient.get(\"https://some.example.com/v1/resource\");\n            // webClient.get() throws HttpServiceUnavailable exception\n            // e.g. try to get this resource 3 times when the HttpServiceUnavailable exception has occurred\n            // we have some assumption, this service can be available later...\n        });\n```\n\n### Fixed Backoff\n\nThis is a **fixed** backoff algorithm implementation.\nThere **each attempt of the operation** will be retried by **the same timeout** if the exception _(or any)_ occurred.\n\n```java\nimport static io.github.pepperkit.retry.Retry.retry;\n\n    retry(3)\n        .backoff(new BackoffFunction.Fixed())\n        .delay(Duration.ofMillis(500))\n        .handle(HttpServiceUnavailable.class)\n        .run(()-\u003e{\n            webClient.get(\"https://some.example.com/v1/resource\");\n            // e.g. try to get this resource 3 times when the HttpServiceUnavailable exception has occurred\n            // we have some assumption, this service can be available later...\n        });\n```\n\n### Randomized Backoff\n\nThis is a **randomized** backoff algorithm implementation.\n\n```java\nimport static io.github.pepperkit.retry.Retry.retry;\n\n    retry(3)\n        .backoff(new BackoffFunction.Randomized(5))\n        .delay(Duration.ofMillis(500))\n        .maxDelay(Duration.ofSeconds(3))\n        .handle(HttpServiceUnavailable.class)\n        .run(()-\u003e{\n            webClient.get(\"https://some.example.com/v1/resource\");\n            // e.g. try to get this resource 3 times when the HttpServiceUnavailable exception has occurred\n            // we have some assumption, this service can be available later...\n        });\n```\n\n\n## License\n\nThe library is licensed  under the terms of the **[MIT License](https://github.com/pepperkit/retry/blob/master/LICENSE)**.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpepperkit%2Fretry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpepperkit%2Fretry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpepperkit%2Fretry/lists"}