Skip to content

Commit ddeaf0a

Browse files
committed
update documentation (idempotency)
1 parent 17af703 commit ddeaf0a

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

docs/utilities/large_messages.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ using the `deleteObject(bucket, key)` API. You can disable the deletion of S3 ob
307307
}
308308
```
309309

310-
!!! tip
310+
!!! tip "Use together with batch module"
311311
This utility works perfectly together with the batch module (`powertools-batch`), especially for SQS:
312312

313313
```java hl_lines="2 5-7 12 15 16" title="Combining batch and large message modules"
@@ -332,6 +332,45 @@ using the `deleteObject(bucket, key)` API. You can disable the deletion of S3 ob
332332
}
333333
```
334334

335+
!!! tip "Use together with idempotency module"
336+
This utility also works together with the idempotency module (`powertools-idempotency`).
337+
You can add both the `@LargeMessage` and `@Idempotent` annotations to the same method.
338+
The `@Idempotent` takes precedence over the `@LargeMessage` annotation.
339+
It means Idempotency module will use the initial raw message (containing the S3 pointer) and not the large message.
340+
Using the large message would end up with potential issues when inserting the data in DynamoDB, where items
341+
are limited to 400 KB (while large messages can be up to 2 GB).
342+
343+
```java hl_lines="6 23-25" title="Combining idempotency and large message modules"
344+
public class SqsBatchHandler implements RequestHandler<SQSEvent, SQSBatchResponse> {
345+
346+
public SqsBatchHandler() {
347+
Idempotency.config().withConfig(
348+
IdempotencyConfig.builder()
349+
.withEventKeyJMESPath("body") // get the body of the message for the idempotency key
350+
.build())
351+
.withPersistenceStore(
352+
DynamoDBPersistenceStore.builder()
353+
.withTableName(System.getenv("IDEMPOTENCY_TABLE"))
354+
.build()
355+
).configure();
356+
}
357+
358+
@Override
359+
public SQSBatchResponse handleRequest(SQSEvent sqsEvent, Context context) {
360+
for (SQSMessage message: event.getRecords()) {
361+
processRawMessage(message, context);
362+
}
363+
return SQSBatchResponse.builder().build();
364+
}
365+
366+
@Idempotent
367+
@LargeMessage
368+
private String processRawMessage(@IdempotencyKey SQSEvent.SQSMessage sqsMessage, Context context) {
369+
// do something with the message
370+
}
371+
}
372+
```
373+
335374
## Customizing S3 client configuration
336375

337376
To interact with S3, the utility creates a default S3 Client :

0 commit comments

Comments
 (0)