Skip to content

Commit d8d3380

Browse files
committed
Clean up SQS
1 parent 42ae2f6 commit d8d3380

File tree

2 files changed

+59
-15
lines changed

2 files changed

+59
-15
lines changed
Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,56 @@
11
## Lambda Powertools for Java - SQS Batch Processing Example
22

3-
Demos setup of SQS Batch processing via Powertools
3+
This project contains an example of Lambda function using the batch processing utilities module of Powertools for AWS Lambda (Java).
4+
For more information on this module, please refer to the [documentation](https://docs.powertools.aws.dev/lambda/java/utilities/batch/).
5+
6+
The project contains two functions:
7+
8+
* [SqsMessageSender](src/main/java/org/demo/sqs/SqsMessageSender.java) - Sends a set of messages to an SQS queue.
9+
This function is triggered every 5 minutes by an EventBridge schedule rule.
10+
* [SqsPoller](src/main/java/org/demo/sqs/SqsPoller.java) - Listens to the same queue, processing items off in batches
11+
12+
The poller intentionally fails intermittently processing messages to demonstrate the replay behaviour of the batch
13+
module:
14+
15+
<details>
16+
<summary>
17+
<b>SqsPoller.java</b>
18+
</summary>
19+
[SqsPoller.java:43](src/main/java/org/demo/sqs/SqsPoller.java)
20+
21+
```java
22+
public String process(SQSMessage message) {
23+
log.info("Processing message with id {}", message.getMessageId());
24+
25+
int nextInt = random.nextInt(100);
26+
27+
if(nextInt <= 10) {
28+
log.info("Randomly picked message with id {} as business validation failure.", message.getMessageId());
29+
throw new IllegalArgumentException("Failed business validation. No point of retrying. Move me to DLQ." + message.getMessageId());
30+
}
31+
32+
if(nextInt > 90) {
33+
log.info("Randomly picked message with id {} as intermittent failure.", message.getMessageId());
34+
throw new RuntimeException("Failed due to intermittent issue. Will be sent back for retry." + message.getMessageId());
35+
}
36+
37+
return "Success";
38+
}
39+
```
40+
41+
</details>
42+
43+
## Deploy the sample application
44+
45+
This sample is based on Serverless Application Model (SAM). To deploy it, check out the instructions for getting
46+
started with SAM in [the examples directory](../README.md)
47+
48+
## Test the application
49+
50+
As the test is pushing through a batch every 5 minutes, we can simply watch the logs to see the batches being processed:
51+
52+
```bash
53+
sam logs --tail --stack-name $MY_STACK
54+
```
55+
56+
As the handler intentionally introduces intermittent failures, we should expect to see error messages too!
Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
# Lambda Powertools for Java - Validation Example
22

3-
This project contains an example of Lambda function using the validation module of Powertools for AWS Lambda (Java). For more information on this module, please refer to the [documentation](https://docs.powertools.aws.dev/lambda-java/utilities/validation/).
3+
This project contains an example of Lambda function using the validation module of Powertools for AWS Lambda (Java).
4+
For more information on this module, please refer to the [documentation](https://docs.powertools.aws.dev/lambda-java/utilities/validation/).
45

56
## Deploy the sample application
67

7-
This sample is based on Serverless Application Model (SAM) and you can use the SAM Command Line Interface (SAM CLI) to build it and deploy it to AWS.
8+
This sample is based on Serverless Application Model (SAM). To deploy it, check out the instructions for getting
9+
started with SAM in [the examples directory](../README.md)
810

9-
To use the SAM CLI, you need the following tools.
11+
## Test the application
1012

11-
* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)
12-
* Java11 - [Install the Java 11](https://docs.aws.amazon.com/corretto/latest/corretto-11-ug/downloads-list.html)
13-
* Maven - [Install Maven](https://maven.apache.org/install.html)
14-
* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community)
15-
16-
To build and deploy your application for the first time, run the following in your shell:
17-
18-
```bash
19-
sam build
20-
sam deploy --guided
21-
```

0 commit comments

Comments
 (0)