Skip to content

Commit 9a6d210

Browse files
authored
Reduce TPS to tagging actions (#54)
* Reduce TPS to tagging actions * Added Versioning policy, heartbeat tag in create request
1 parent dc5ca62 commit 9a6d210

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

VERSIONING.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Versioning Policy
2+
3+
We use a three-part X.Y.Z (Major.Minor.Patch) versioning definition, as follows:
4+
* X (Major) version changes are significant and expected to break backwards compatibility.
5+
* Y (Minor) version changes are moderate changes. These include:
6+
* Significant non-breaking feature additions.
7+
* Any change to the version of a dependency.
8+
* Possible backwards-incompatible changes. These changes will be noted and explained in detail in the release notes.
9+
* Z (Patch) version changes are small changes. These changes will not break backwards compatibility.
10+
* Z releases will also include warning of upcoming breaking changes, whenever possible.
11+
12+
## What this means for you
13+
14+
We recommend running the most recent version. Here are our suggestions for managing updates:
15+
16+
* X changes will require some effort to incorporate.
17+
* Y changes will not require significant effort to incorporate.
18+
* If you have good unit and integration tests, these changes are generally safe to pick up automatically.
19+
* Z changes will not require any changes to your code. Z changes are intended to be picked up automatically.
20+
* Good unit and integration tests are always recommended.

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<dependency>
3737
<groupId>com.amazonaws</groupId>
3838
<artifactId>aws-java-sdk-bom</artifactId>
39-
<version>1.11.446</version>
39+
<version>1.11.819</version>
4040
<type>pom</type>
4141
<scope>import</scope>
4242
</dependency>

src/main/java/com/amazonaws/services/sqs/AmazonSQSIdleQueueDeletingClient.java

+9-12
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
import java.util.List;
77
import java.util.Map;
88
import java.util.Optional;
9-
import java.util.concurrent.ConcurrentHashMap;
10-
import java.util.concurrent.Executors;
11-
import java.util.concurrent.Future;
12-
import java.util.concurrent.ScheduledExecutorService;
13-
import java.util.concurrent.TimeUnit;
9+
import java.util.concurrent.*;
1410
import java.util.function.Consumer;
1511

1612
import com.amazonaws.services.sqs.model.QueueNameExistsException;
@@ -190,17 +186,17 @@ public CreateQueueResult createQueue(CreateQueueRequest request) {
190186
throw new IllegalArgumentException();
191187
}
192188

189+
String retentionPeriodString = retentionPeriod.get().toString();
190+
long currentTimestamp = System.currentTimeMillis();
193191
CreateQueueRequest superRequest = request.clone()
194192
.withQueueName(queueName)
195-
.withAttributes(attributes);
193+
.withAttributes(attributes)
194+
.addTagsEntry(IDLE_QUEUE_RETENTION_PERIOD_TAG, retentionPeriodString)
195+
.addTagsEntry(LAST_HEARTBEAT_TIMESTAMP_TAG, String.valueOf(currentTimestamp));
196196

197197
CreateQueueResult result = super.createQueue(superRequest);
198198
String queueUrl = result.getQueueUrl();
199199

200-
String retentionPeriodString = retentionPeriod.get().toString();
201-
amazonSqsToBeExtended.tagQueue(queueUrl,
202-
Collections.singletonMap(IDLE_QUEUE_RETENTION_PERIOD_TAG, retentionPeriodString));
203-
204200
// TODO-RS: Filter more carefully to all attributes valid for createQueue
205201
List<String> attributeNames = Arrays.asList(QueueAttributeName.ReceiveMessageWaitTimeSeconds.toString(),
206202
QueueAttributeName.VisibilityTimeout.toString());
@@ -210,8 +206,9 @@ public CreateQueueResult createQueue(CreateQueueRequest request) {
210206
QueueMetadata metadata = new QueueMetadata(queueName, queueUrl, createdAttributes);
211207
queues.put(queueUrl, metadata);
212208

213-
metadata.heartbeater = executor.scheduleAtFixedRate(() -> heartbeatToQueue(queueUrl),
214-
0, heartbeatIntervalSeconds, TimeUnit.SECONDS);
209+
long initialDelay = ThreadLocalRandom.current().nextLong(heartbeatIntervalSeconds);
210+
metadata.heartbeater = executor.scheduleAtFixedRate(() -> heartbeatToQueue(queueUrl),
211+
initialDelay, heartbeatIntervalSeconds, TimeUnit.SECONDS);
215212

216213
return result;
217214
}

src/test/java/com/amazonaws/services/sqs/util/SQSQueueUtilsTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public void sendMessageRequestCopyWithExtraAttributes() throws IllegalAccessExce
2828
.withDelaySeconds(5)
2929
.withMessageAttributes(Collections.emptyMap())
3030
.withMessageDeduplicationId("dedup")
31-
.withMessageGroupId("groupId");
31+
.withMessageGroupId("groupId")
32+
.withMessageSystemAttributes(Collections.emptyMap());
3233

3334
SendMessageRequest sendMessageRequestCopy =
3435
SQSQueueUtils.copyWithExtraAttributes(sendMessageRequest, Collections.emptyMap());
@@ -48,7 +49,8 @@ public void createQueueRequestCopyWithExtraAttributes() throws IllegalAccessExce
4849

4950
CreateQueueRequest createQueueRequest = new CreateQueueRequest()
5051
.withQueueName("queueName")
51-
.withAttributes(Collections.emptyMap());
52+
.withAttributes(Collections.emptyMap())
53+
.withTags(Collections.emptyMap());
5254

5355
CreateQueueRequest createQueueRequestCopy =
5456
SQSQueueUtils.copyWithExtraAttributes(createQueueRequest, Collections.emptyMap());

0 commit comments

Comments
 (0)