@@ -104,5 +104,53 @@ To disable deletion of payloads setting the following annotation parameter:
104
104
``` java
105
105
@LargeMessageHandler (deletePayloads = false )
106
106
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
+ }
107
152
}
108
- ```
153
+ ```
154
+
155
+
156
+
0 commit comments