-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pankaj Agrawal
committed
Aug 12, 2021
1 parent
2a2f1c0
commit b494fa2
Showing
7 changed files
with
293 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...on/lambda/powertools/sqs/handlers/SqsMessageHandlerWithNonRetryableHandlerWithDelete.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package software.amazon.lambda.powertools.sqs.handlers; | ||
|
||
import com.amazonaws.services.lambda.runtime.Context; | ||
import com.amazonaws.services.lambda.runtime.RequestHandler; | ||
import com.amazonaws.services.lambda.runtime.events.SQSEvent; | ||
import software.amazon.lambda.powertools.sqs.SqsBatch; | ||
import software.amazon.lambda.powertools.sqs.SqsMessageHandler; | ||
|
||
import static com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage; | ||
import static software.amazon.lambda.powertools.sqs.internal.SqsMessageBatchProcessorAspectTest.mockedRandom; | ||
|
||
public class SqsMessageHandlerWithNonRetryableHandlerWithDelete implements RequestHandler<SQSEvent, String> { | ||
|
||
@Override | ||
@SqsBatch(value = InnerMessageHandler.class, | ||
nonRetryableExceptions = {IllegalStateException.class, IllegalArgumentException.class}, | ||
deleteNonRetryableMessageFromQueue = true) | ||
public String handleRequest(final SQSEvent sqsEvent, | ||
final Context context) { | ||
return "Success"; | ||
} | ||
|
||
private class InnerMessageHandler implements SqsMessageHandler<Object> { | ||
|
||
@Override | ||
public String process(SQSMessage message) { | ||
if(message.getMessageId().isEmpty()) { | ||
throw new IllegalArgumentException("Invalid message and was moved to DLQ"); | ||
} | ||
|
||
if("2e1424d4-f796-459a-9696-9c92662ba5da".equals(message.getMessageId())) { | ||
throw new RuntimeException("Invalid message and should be reprocessed"); | ||
} | ||
|
||
mockedRandom.nextInt(); | ||
return "Success"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
powertools-sqs/src/test/resources/threeMessageSqsBatchEvent.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{ | ||
"records": [ | ||
{ | ||
"messageId": "059f36b4-87a3-44ab-83d2-661975830a7d", | ||
"receiptHandle": "AQEBwJnKyrHigUMZj6rYigCgxlaS3SLy0a...", | ||
"body": "Test message.", | ||
"attributes": { | ||
"ApproximateReceiveCount": "1", | ||
"SentTimestamp": "1545082649183", | ||
"SenderId": "AIDAIENQZJOLO23YVJ4VO", | ||
"ApproximateFirstReceiveTimestamp": "1545082649185" | ||
}, | ||
"messageAttributes": {}, | ||
"md5OfBody": "e4e68fb7bd0e697a0ae8f1bb342846b3", | ||
"eventSource": "aws:sqs", | ||
"eventSourceArn": "arn:aws:sqs:us-east-1:906126917321:sqs-lambda-MySqsQueue-4DYWWJIE97N5", | ||
"awsRegion": "us-east-2" | ||
}, | ||
{ | ||
"messageId": "2e1424d4-f796-459a-8184-9c92662be6da", | ||
"receiptHandle": "AQEBzWwaftRI0KuVm4tP+/7q1rGgNqicHq...", | ||
"body": "Test message.", | ||
"attributes": { | ||
"ApproximateReceiveCount": "1", | ||
"SentTimestamp": "1545082650636", | ||
"SenderId": "AIDAIENQZJOLO23YVJ4VO", | ||
"ApproximateFirstReceiveTimestamp": "1545082650649" | ||
}, | ||
"messageAttributes": { | ||
"Attribute3" : { | ||
"binaryValue" : "MTEwMA==", | ||
"dataType" : "Binary" | ||
}, | ||
"Attribute2" : { | ||
"stringValue" : "123", | ||
"dataType" : "Number" | ||
}, | ||
"Attribute1" : { | ||
"stringValue" : "AttributeValue1", | ||
"dataType" : "String" | ||
} | ||
}, | ||
"md5OfBody": "e4e68fb7bd0e697a0ae8f1bb342846b3", | ||
"eventSource": "aws:sqs", | ||
"eventSourceArn": "arn:aws:sqs:us-east-1:906126917321:sqs-lambda-MySqsQueue-4DYWWJIE97N5", | ||
"awsRegion": "us-east-2" | ||
}, | ||
{ | ||
"messageId": "2e1424d4-f796-459a-9696-9c92662ba5da", | ||
"receiptHandle": "AQEBzWwaftRI0KuVm4tP+/7q1rGgNqicHq...", | ||
"body": "Test message.", | ||
"attributes": { | ||
"ApproximateReceiveCount": "1", | ||
"SentTimestamp": "1545082650636", | ||
"SenderId": "AIDAIENQZJOLO23YVJ4VO", | ||
"ApproximateFirstReceiveTimestamp": "1545082650649" | ||
}, | ||
"messageAttributes": { | ||
"Attribute2" : { | ||
"stringValue" : "123", | ||
"dataType" : "Number" | ||
} | ||
}, | ||
"md5OfBody": "e4e68fb7bd0e697a0ae8f1bb342846b3", | ||
"eventSource": "aws:sqs", | ||
"eventSourceArn": "arn:aws:sqs:us-east-1:906126917321:sqs-lambda-MySqsQueue-4DYWWJIE97N5", | ||
"awsRegion": "us-east-2" | ||
} | ||
] | ||
} |