@@ -104,5 +104,54 @@ 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
+
107
108
}
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