Skip to content

Commit daf886c

Browse files
author
Pankaj Agrawal
committed
Updated doc for utility method
1 parent f6e34df commit daf886c

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

docs/content/utilities/sqs_large_message_handling.mdx

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,54 @@ To disable deletion of payloads setting the following annotation parameter:
104104
```java
105105
@LargeMessageHandler(deletePayloads=false)
106106
public class SqsMessageHandler implements RequestHandler<SQSEvent, String> {
107+
107108
}
108-
```
109+
```
110+
111+
## Utility
112+
113+
If you want to avoid using annotation and have control over error that can happen during payload enrichment.
114+
115+
`PowertoolsSqs.enrichedMessageFromS3()` provides you access with list of `SQSMessage` object enriched from S3 payload.
116+
Original `SQSEvent` object is never mutated. You can also control if the S3 payload should be deleted after successful
117+
processing. You can enrich messages from S3 with below code:
118+
119+
```java
120+
public class SqsMessageHandler implements RequestHandler<SQSEvent, String> {
121+
122+
@Override
123+
@LargeMessageHandler
124+
public String handleRequest(SQSEvent sqsEvent, Context context) {
125+
126+
Map<String, String> sqsMessage = PowertoolsSqs.enrichedMessageFromS3(sqsEvent, sqsMessages -> {
127+
// Some business logic
128+
Map<String, String> someBusinessLogic = new HashMap<>();
129+
someBusinessLogic.put("Message", sqsMessages.get(0).getBody());
130+
return someBusinessLogic;
131+
});
132+
133+
// Do not delete payload after processing.
134+
Map<String, String> sqsMessage = PowertoolsSqs.enrichedMessageFromS3(sqsEvent, false, sqsMessages -> {
135+
// Some business logic
136+
Map<String, String> someBusinessLogic = new HashMap<>();
137+
someBusinessLogic.put("Message", sqsMessages.get(0).getBody());
138+
return someBusinessLogic;
139+
});
140+
141+
// Better control over exception during enrichment
142+
try {
143+
// Do not delete payload after processing.
144+
PowertoolsSqs.enrichedMessageFromS3(sqsEvent, false, sqsMessages -> {
145+
// Some business logic
146+
});
147+
} catch (FailedProcessingLargePayloadException e) {
148+
// handle any exception.
149+
}
150+
151+
return "ok";
152+
}
153+
}
154+
```
155+
156+
157+

0 commit comments

Comments
 (0)