### Build and Verify Project
Source: https://github.com/josipmusa/idempotency4j/blob/main/CONTRIBUTING.md
Run this command to compile, test, and check formatting for a clean build. It's the baseline for any contribution.
```bash
mvn verify
```
--------------------------------
### Add Spring Boot Starter Dependency
Source: https://github.com/josipmusa/idempotency4j/blob/main/README.md
Include the idempotency-spring-boot-starter and a storage backend dependency in your Maven project. Replace VERSION with the latest version.
```xml
io.github.josipmusa
idempotency-spring-boot-starter
VERSION
io.github.josipmusa
idempotency-jdbc
VERSION
```
--------------------------------
### Run All Tests
Source: https://github.com/josipmusa/idempotency4j/blob/main/CONTRIBUTING.md
Execute all unit and integration tests for the project. Ensure Docker is running if testing provider modules that use Testcontainers.
```bash
mvn test
```
--------------------------------
### Apply Code Formatting
Source: https://github.com/josipmusa/idempotency4j/blob/main/CONTRIBUTING.md
Automatically fix any code formatting violations enforced by Spotless and Palantir Java Format before committing.
```bash
mvn spotless:apply
```
--------------------------------
### Test Specific Module
Source: https://github.com/josipmusa/idempotency4j/blob/main/CONTRIBUTING.md
Use these commands to test a specific module and its upstream dependencies without running the full test suite. Ensure SNAPSHOT versions resolve correctly.
```bash
mvn test -pl idempotency-core -am
```
```bash
mvn test -pl providers/idempotency-jdbc -am
```
--------------------------------
### Use BOM for Dependency Management
Source: https://github.com/josipmusa/idempotency4j/blob/main/README.md
Utilize the idempotency-bom to manage versions of all idempotency modules in your Maven project.
```xml
io.github.josipmusa
idempotency-bom
VERSION
pom
import
```
--------------------------------
### Client Request with Idempotency-Key Header
Source: https://github.com/josipmusa/idempotency4j/blob/main/README.md
Clients must include a client-generated Idempotency-Key in the request header for idempotency to be enforced. The key should be a UUID.
```http
POST /payments
Idempotency-Key: 550e8400-e29b-41d4-a716-446655440000
Content-Type: application/json
{ "amount": 100, "currency": "USD" }
```
--------------------------------
### Idempotency Configuration Properties
Source: https://github.com/josipmusa/idempotency4j/blob/main/README.md
Configure Idempotency4j globally using YAML properties. These settings can be overridden by per-endpoint annotation values.
```yaml
idempotency:
key-header: Idempotency-Key # Header name carrying the key. Default: Idempotency-Key
default-ttl: PT24H # Default TTL for stored responses. Default: 24h
default-lock-timeout: PT10S # Default lock timeout. Default: 10s
max-body-bytes: 1048576 # Max request body size to fingerprint in bytes. Default: 1 MiB
filter-order: 0 # Order of the idempotency filter in the filter chain. Default: 0
purge:
enabled: true # Whether to register the purge scheduler. Default: true
cron: "0 0 * * * *" # Cron expression for purging expired records. Default: hourly
```
--------------------------------
### Idempotent Annotation Configuration
Source: https://github.com/josipmusa/idempotency4j/blob/main/README.md
Configure the `@Idempotent` annotation with TTL, lock timeout, and requirement settings. TTL and lock timeout use ISO-8601 duration format.
```java
@Idempotent(
ttl = "PT24H", // How long to keep the stored response (ISO-8601). Default: 24h
lockTimeout = "PT10S", // How long a concurrent duplicate waits. Default: 10s
required = true // Whether a missing key header is an error. Default: true
)
```
--------------------------------
### Register Custom ResponseSanitizer Bean
Source: https://github.com/josipmusa/idempotency4j/blob/main/README.md
Register a ResponseSanitizer bean to strip or redact sensitive fields from HTTP response bodies before they are stored for idempotency. The default implementation does nothing.
```java
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpHeaders;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
// Assuming StoredResponse and ResponseSanitizer are defined elsewhere
// import com.example.idempotency.StoredResponse;
// import com.example.idempotency.ResponseSanitizer;
public class IdempotencyConfig {
@Bean
public ResponseSanitizer responseSanitizer() {
return response -> {
// Remove sensitive headers, redact body, etc.
Map> headers = new HashMap<>(response.headers());
headers.remove("Set-Cookie");
return new StoredResponse(response.statusCode(), headers, response.body(), response.completedAt());
};
}
}
```
--------------------------------
### Annotate Endpoints for Idempotency
Source: https://github.com/josipmusa/idempotency4j/blob/main/README.md
Apply the @Idempotent annotation to Spring controller methods that require idempotency. This ensures that requests with the same Idempotency-Key are processed only once.
```java
@PostMapping("/payments")
@Idempotent
public ResponseEntity createPayment(@RequestBody PaymentRequest request) {
// Runs exactly once per unique Idempotency-Key value.
// Subsequent identical requests get the stored response replayed.
return ResponseEntity.ok(paymentService.charge(request));
}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.