# est-spi-retry **Repository Path**: est-spi/retry ## Basic Information - **Project Name**: est-spi-retry - **Description**: No description available - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-15 - **Last Updated**: 2026-03-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # EST SPI Retry [English Version](README.en.md) ## EST SPI 重试模块 est-spi-retry ?EST SPI 框架的重试模块,提供了灵活的重试机制? ### 核心功能 #### RetryPolicy - 重试策略接口 重试策略的统一接口,定义了是否可以重试、获取延迟时间等方法? #### FixedDelayPolicy - 固定延迟策略 固定延迟重试策略,每次重试之间间隔固定时间? #### ExponentialBackoffPolicy - 指数退避策? 指数退避重试策略,每次重试延迟时间按指数增长? #### RetryTemplate - 重试模板 重试模板,使用指定的重试策略来执行操作? ### 快速开? #### 使用固定延迟策略 ```java import ltd.idcu.est.spi.retry.RetryTemplate; import ltd.idcu.est.spi.retry.FixedDelayPolicy; import ltd.idcu.est.spi.retry.RetryPolicy; public class Example { public static void main(String[] args) throws Exception { RetryPolicy policy = FixedDelayPolicy.of(3, 1000L); RetryTemplate template = RetryTemplate.of(policy); template.execute(() -> { System.out.println("Executing operation..."); return "Success"; }); } } ``` #### 使用指数退避策? ```java import ltd.idcu.est.spi.retry.RetryTemplate; import ltd.idcu.est.spi.retry.ExponentialBackoffPolicy; import ltd.idcu.est.spi.retry.RetryPolicy; public class Example { public static void main(String[] args) throws Exception { RetryPolicy policy = ExponentialBackoffPolicy.of(5, 1000L, 10000L, 2.0); RetryTemplate template = RetryTemplate.of(policy); String result = template.execute(() -> { System.out.println("Executing operation..."); return "Success"; }); System.out.println(result); } } ``` #### 使用默认指数退避策? ```java import ltd.idcu.est.spi.retry.RetryTemplate; import ltd.idcu.est.spi.retry.ExponentialBackoffPolicy; public class Example { public static void main(String[] args) throws Exception { ExponentialBackoffPolicy policy = ExponentialBackoffPolicy.ofDefaults(3); RetryTemplate template = RetryTemplate.of(policy); template.execute(() -> { System.out.println("Executing operation..."); }); } } ``` #### 处理失败场景 ```java import ltd.idcu.est.spi.retry.RetryTemplate; import ltd.idcu.est.spi.retry.FixedDelayPolicy; public class Example { private static int attemptCount = 0; public static void main(String[] args) { RetryTemplate template = RetryTemplate.of(FixedDelayPolicy.of(3, 500L)); try { template.execute(() -> { attemptCount++; System.out.println("Attempt: " + attemptCount); if (attemptCount < 3) { throw new RuntimeException("Temporary failure"); } System.out.println("Success!"); return null; }); } catch (Exception e) { System.err.println("Failed after retries: " + e.getMessage()); } } } ``` ### Maven 依赖 ```xml ltd.idcu.est.spi est-spi-retry 1.0.0 ``` ### 许可? MIT License