Skip to content

Commit 44f09fc

Browse files
committed
refactor: enhance IdempotencyKeyResolver to support hybrid idempotency strategy
1 parent 4a616b5 commit 44f09fc

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

fineract-core/src/main/java/org/apache/fineract/commands/service/IdempotencyKeyResolver.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,28 @@ public class IdempotencyKeyResolver {
3030

3131
private final FineractRequestContextHolder fineractRequestContextHolder;
3232

33+
private final DeterministicIdempotencyKeyGenerator deterministicGenerator;
34+
3335
private final IdempotencyKeyGenerator idempotencyKeyGenerator;
3436

3537
public String resolve(CommandWrapper wrapper) {
36-
return Optional.ofNullable(wrapper.getIdempotencyKey()).orElseGet(() -> getAttribute().orElseGet(idempotencyKeyGenerator::create));
38+
39+
// If wrapper already has key → use it
40+
if (wrapper.getIdempotencyKey() != null) {
41+
return wrapper.getIdempotencyKey();
42+
}
43+
44+
// If request attribute exists (internal retry)
45+
Optional<String> attributeKey = getAttribute();
46+
if (attributeKey.isPresent()) {
47+
return attributeKey.get();
48+
}
49+
50+
// hybrid logic (external retry)
51+
return deterministicGenerator.generate(wrapper);
3752
}
3853

54+
3955
private Optional<String> getAttribute() {
4056
return Optional.ofNullable(fineractRequestContextHolder.getAttribute(SynchronousCommandProcessingService.IDEMPOTENCY_KEY_ATTRIBUTE))
4157
.map(String::valueOf);

0 commit comments

Comments
 (0)