### Configure Redis Connection Source: https://github.com/atlancia-labs/spring-idempotency-kit/blob/main/Readme.md Configure your Redis connection details in application.properties or application.yml. ```yaml spring: data: redis: host: localhost port: 6379 ``` -------------------------------- ### Global Idempotency Configuration Source: https://github.com/atlancia-labs/spring-idempotency-kit/blob/main/Readme.md Configure global default settings for idempotency, including TTL, concurrent strategy, and failure strategy. ```yaml spring: idempotency: default-ttl: 24 # TTL value (default: 24) default-time-unit: hours # TTL unit (default: hours) default-on-concurrent: reject # REJECT or WAIT (default: reject) default-on-failure: fail-open # FAIL_OPEN or FAIL_CLOSED (default: fail-open) key-prefix: "idempotency:" # Redis key prefix (default: "idempotency:") lock-timeout: 30s # Distributed lock TTL (default: 30s) wait-timeout: 10s # Max wait time for WAIT strategy (default: 10s) wait-poll-initial-interval: 100ms # Initial poll interval (default: 100ms) wait-poll-max-interval: 1s # Max poll interval after backoff (default: 1s) ``` -------------------------------- ### Add Dependency (Gradle Kotlin) Source: https://github.com/atlancia-labs/spring-idempotency-kit/blob/main/Readme.md Add the spring-idempotency-kit dependency to your build.gradle.kts file. ```kotlin dependencies { implementation("io.github.atlancia-labs:spring-idempotency-kit:0.1.0") } ``` -------------------------------- ### Register Custom IdempotencyStorage Bean Source: https://github.com/atlancia-labs/spring-idempotency-kit/blob/main/Readme.md Implement the IdempotencyStorage interface and register it as a Spring bean to use a custom storage backend. The auto-configuration will automatically back off. ```java @Bean public IdempotencyStorage customStorage() { return new MyIdempotencyStorage(); } ``` -------------------------------- ### Concurrent Request Handling with WAIT Strategy Source: https://github.com/atlancia-labs/spring-idempotency-kit/blob/main/Readme.md Configure a method to use the WAIT strategy for concurrent requests, causing subsequent requests to poll until the first completes. ```java @Idempotent(headerName = "Idempotency-Key", onConcurrent = ConcurrentStrategy.WAIT) public Response slowOperation(Request request) { // second concurrent request will wait for this to finish } ``` -------------------------------- ### Idempotent Method with Header Key Source: https://github.com/atlancia-labs/spring-idempotency-kit/blob/main/Readme.md Annotate a method with @Idempotent to ensure it executes only once per unique key extracted from an HTTP header. ```java @Idempotent(headerName = "Idempotency-Key") public OrderResponse createOrder(OrderRequest request) { // executed once per unique Idempotency-Key header value } ``` -------------------------------- ### Idempotent Method with SpEL Key Source: https://github.com/atlancia-labs/spring-idempotency-kit/blob/main/Readme.md Annotate a method with @Idempotent to ensure it executes only once per unique key extracted using SpEL expressions from method arguments. ```java @Idempotent(key = "#request.id") public PaymentResponse processPayment(PaymentRequest request) { // executed once per unique request.id } ``` -------------------------------- ### IdempotencyStorage Interface Definition Source: https://github.com/atlancia-labs/spring-idempotency-kit/blob/main/Readme.md The core interface for idempotency storage. Implementations must handle atomic operations, lock expiry, and token-aware release. ```java public interface IdempotencyStorage { Optional get(String key); String acquireLock(String key, Duration lockTtl); // returns lock token, or null if already held void store(String key, IdempotencyResult result, Duration ttl); void releaseLock(String key, String lockToken); // token-aware release default long keyCount() { return -1; } // override to enable idempotency.keys.count gauge } ``` -------------------------------- ### Per-Method Failure Strategy Override Source: https://github.com/atlancia-labs/spring-idempotency-kit/blob/main/Readme.md Override the default failure strategy for a specific method using the onFailure attribute in the @Idempotent annotation. ```java @Idempotent(key = "#id", onFailure = FailureStrategy.FAIL_CLOSED) public Response criticalPayment(String id) { ... } ``` -------------------------------- ### Per-Method TTL Override Source: https://github.com/atlancia-labs/spring-idempotency-kit/blob/main/Readme.md Override the default TTL for a specific method using the ttl and timeUnit attributes in the @Idempotent annotation. ```java @Idempotent(key = "#id", ttl = 1, timeUnit = TimeUnit.MINUTES) public Response shortLivedOperation(String id) { ... } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.