Skip to content

Commit 8ac9396

Browse files
author
Pankaj Agrawal
committed
Updated doc for utility method
1 parent dd3a715 commit 8ac9396

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

docs/content/utilities/sqs_large_message_handling.mdx

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,53 @@ 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+
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+
public String handleRequest(SQSEvent sqsEvent, Context context) {
124+
125+
Map<String, String> sqsMessage = PowertoolsSqs.enrichedMessageFromS3(sqsEvent, sqsMessages -> {
126+
// Some business logic
127+
Map<String, String> someBusinessLogic = new HashMap<>();
128+
someBusinessLogic.put("Message", sqsMessages.get(0).getBody());
129+
return someBusinessLogic;
130+
});
131+
132+
// Do not delete payload after processing.
133+
Map<String, String> sqsMessage = PowertoolsSqs.enrichedMessageFromS3(sqsEvent, false, sqsMessages -> {
134+
// Some business logic
135+
Map<String, String> someBusinessLogic = new HashMap<>();
136+
someBusinessLogic.put("Message", sqsMessages.get(0).getBody());
137+
return someBusinessLogic;
138+
});
139+
140+
// Better control over exception during enrichment
141+
try {
142+
// Do not delete payload after processing.
143+
PowertoolsSqs.enrichedMessageFromS3(sqsEvent, false, sqsMessages -> {
144+
// Some business logic
145+
});
146+
} catch (FailedProcessingLargePayloadException e) {
147+
// handle any exception.
148+
}
149+
150+
return "ok";
151+
}
107152
}
108-
```
153+
```
154+
155+
156+

0 commit comments

Comments
 (0)