33
33
import static software .amazon .lambda .powertools .sqs .internal .SqsLargeMessageAspect .processMessages ;
34
34
35
35
/**
36
- * A class of helper functions to add additional functionality to LargeMessageHandler.
37
- * <p>
38
- * {@see PowertoolsLogging}
36
+ * A class of helper functions to add additional functionality to {@link SQSEvent} processing.
39
37
*/
40
38
public final class PowertoolsSqs {
41
39
private static final Log LOG = LogFactory .getLog (PowertoolsSqs .class );
@@ -99,22 +97,64 @@ public static void defaultSqsClient(SqsClient client) {
99
97
}
100
98
101
99
/**
102
- * @param event
103
- * @param handler
104
- * @param <R>
105
- * @return
100
+ * This utility method is used to processes each {@link SQSMessage} inside received {@link SQSEvent}
101
+ *
102
+ * <p>
103
+ * Utility will take care of calling {@link SqsMessageHandler#process(SQSMessage)} method for each {@link SQSMessage}
104
+ * in the received {@link SQSEvent}
105
+ * </p>
106
+ *
107
+ * </p>
108
+ * If any exception is thrown from {@link SqsMessageHandler#process(SQSMessage)} during processing of a messages,
109
+ * Utility will take care of deleting all the successful messages from SQS. When one or more single message fails
110
+ * processing due to exception thrown from {@link SqsMessageHandler#process(SQSMessage)}
111
+ * {@link SQSBatchProcessingException} is thrown with all the details of successful and failed messages.
112
+ * <p>
113
+ * If all the messages are successfully processes, No SQS messages are deleted explicitly but is rather delegated to
114
+ * Lambda execution context for deletion.
115
+ * </p>
116
+ *
117
+ * <p>
118
+ * If you dont want to utility to throw {@link SQSBatchProcessingException} in case of failures but rather suppress
119
+ * it, Refer {@link PowertoolsSqs#batchProcessor(SQSEvent, boolean, Class)}
120
+ * </p>
121
+ *
122
+ * @param event {@link SQSEvent} received by lambda function.
123
+ * @param handler Class implementing {@link SqsMessageHandler} which will be called for each message in event.
124
+ * @return List of values returned by {@link SqsMessageHandler#process(SQSMessage)} while processing each message.
125
+ * @throws SQSBatchProcessingException if some messages fail during processing.
106
126
*/
107
127
public static <R > List <R > batchProcessor (final SQSEvent event ,
108
128
final Class <? extends SqsMessageHandler <R >> handler ) {
109
129
return batchProcessor (event , false , handler );
110
130
}
111
131
112
132
/**
113
- * @param event
114
- * @param suppressException
115
- * @param handler
116
- * @param <R>
117
- * @return
133
+ * This utility method is used to processes each {@link SQSMessage} inside received {@link SQSEvent}
134
+ *
135
+ * <p>
136
+ * Utility will take care of calling {@link SqsMessageHandler#process(SQSMessage)} method for each {@link SQSMessage}
137
+ * in the received {@link SQSEvent}
138
+ * </p>
139
+ *
140
+ * </p>
141
+ * If any exception is thrown from {@link SqsMessageHandler#process(SQSMessage)} during processing of a messages,
142
+ * Utility will take care of deleting all the successful messages from SQS. When one or more single message fails
143
+ * processing due to exception thrown from {@link SqsMessageHandler#process(SQSMessage)}
144
+ * {@link SQSBatchProcessingException} is thrown with all the details of successful and failed messages.
145
+ * <p>
146
+ * Exception can also be suppressed if desired.
147
+ * <p>
148
+ * If all the messages are successfully processes, No SQS messages are deleted explicitly but is rather delegated to
149
+ * Lambda execution context for deletion.
150
+ * </p>
151
+ *
152
+ * @param event {@link SQSEvent} received by lambda function.
153
+ * @param suppressException if this is set to true, No {@link SQSBatchProcessingException} is thrown even on failed
154
+ * messages.
155
+ * @param handler Class implementing {@link SqsMessageHandler} which will be called for each message in event.
156
+ * @return List of values returned by {@link SqsMessageHandler#process(SQSMessage)} while processing each message.
157
+ * @throws SQSBatchProcessingException if some messages fail during processing and no suppression enabled.
118
158
*/
119
159
public static <R > List <R > batchProcessor (final SQSEvent event ,
120
160
final boolean suppressException ,
@@ -125,22 +165,64 @@ public static <R> List<R> batchProcessor(final SQSEvent event,
125
165
}
126
166
127
167
/**
128
- * @param event
129
- * @param handler
130
- * @param <R>
131
- * @return
168
+ * This utility method is used to processes each {@link SQSMessage} inside received {@link SQSEvent}
169
+ *
170
+ * <p>
171
+ * Utility will take care of calling {@link SqsMessageHandler#process(SQSMessage)} method for each {@link SQSMessage}
172
+ * in the received {@link SQSEvent}
173
+ * </p>
174
+ *
175
+ * </p>
176
+ * If any exception is thrown from {@link SqsMessageHandler#process(SQSMessage)} during processing of a messages,
177
+ * Utility will take care of deleting all the successful messages from SQS. When one or more single message fails
178
+ * processing due to exception thrown from {@link SqsMessageHandler#process(SQSMessage)}
179
+ * {@link SQSBatchProcessingException} is thrown with all the details of successful and failed messages.
180
+ * <p>
181
+ * If all the messages are successfully processes, No SQS messages are deleted explicitly but is rather delegated to
182
+ * Lambda execution context for deletion.
183
+ * </p>
184
+ *
185
+ * <p>
186
+ * If you dont want to utility to throw {@link SQSBatchProcessingException} in case of failures but rather suppress
187
+ * it, Refer {@link PowertoolsSqs#batchProcessor(SQSEvent, boolean, SqsMessageHandler)}
188
+ * </p>
189
+ *
190
+ * @param event {@link SQSEvent} received by lambda function.
191
+ * @param handler Instance of class implementing {@link SqsMessageHandler} which will be called for each message in event.
192
+ * @return List of values returned by {@link SqsMessageHandler#process(SQSMessage)} while processing each message-
193
+ * @throws SQSBatchProcessingException if some messages fail during processing.
132
194
*/
133
195
public static <R > List <R > batchProcessor (final SQSEvent event ,
134
196
final SqsMessageHandler <R > handler ) {
135
197
return batchProcessor (event , false , handler );
136
198
}
137
199
138
200
/**
139
- * @param event
140
- * @param suppressException
141
- * @param handler
142
- * @param <R>
143
- * @return
201
+ * This utility method is used to processes each {@link SQSMessage} inside received {@link SQSEvent}
202
+ *
203
+ * <p>
204
+ * Utility will take care of calling {@link SqsMessageHandler#process(SQSMessage)} method for each {@link SQSMessage}
205
+ * in the received {@link SQSEvent}
206
+ * </p>
207
+ *
208
+ * </p>
209
+ * If any exception is thrown from {@link SqsMessageHandler#process(SQSMessage)} during processing of a messages,
210
+ * Utility will take care of deleting all the successful messages from SQS. When one or more single message fails
211
+ * processing due to exception thrown from {@link SqsMessageHandler#process(SQSMessage)}
212
+ * {@link SQSBatchProcessingException} is thrown with all the details of successful and failed messages.
213
+ * <p>
214
+ * Exception can also be suppressed if desired.
215
+ * <p>
216
+ * If all the messages are successfully processes, No SQS messages are deleted explicitly but is rather delegated to
217
+ * Lambda execution context for deletion.
218
+ * </p>
219
+ *
220
+ * @param event {@link SQSEvent} received by lambda function.
221
+ * @param suppressException if this is set to true, No {@link SQSBatchProcessingException} is thrown even on failed
222
+ * messages.
223
+ * @param handler Instance of class implementing {@link SqsMessageHandler} which will be called for each message in event.
224
+ * @return List of values returned by {@link SqsMessageHandler#process(SQSMessage)} while processing each message.
225
+ * @throws SQSBatchProcessingException if some messages fail during processing and no suppression enabled.
144
226
*/
145
227
public static <R > List <R > batchProcessor (final SQSEvent event ,
146
228
final boolean suppressException ,
@@ -158,12 +240,7 @@ public static <R> List<R> batchProcessor(final SQSEvent event,
158
240
}
159
241
}
160
242
161
- try {
162
- batchContext .processSuccessAndReset (suppressException );
163
- } catch (SQSBatchProcessingException e ) {
164
- e .addSuccessMessageReturnValues (handlerReturn );
165
- throw e ;
166
- }
243
+ batchContext .processSuccessAndHandleFailed (handlerReturn , suppressException );
167
244
168
245
return handlerReturn ;
169
246
}
0 commit comments