Skip to content

Commit

Permalink
Reduce TPS to tagging actions (#54)
Browse files Browse the repository at this point in the history
* Reduce TPS to tagging actions

* Added Versioning policy, heartbeat tag in create request
  • Loading branch information
adam-aws authored Jul 15, 2020
1 parent dc5ca62 commit 9a6d210
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
20 changes: 20 additions & 0 deletions VERSIONING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Versioning Policy

We use a three-part X.Y.Z (Major.Minor.Patch) versioning definition, as follows:
* X (Major) version changes are significant and expected to break backwards compatibility.
* Y (Minor) version changes are moderate changes. These include:
* Significant non-breaking feature additions.
* Any change to the version of a dependency.
* Possible backwards-incompatible changes. These changes will be noted and explained in detail in the release notes.
* Z (Patch) version changes are small changes. These changes will not break backwards compatibility.
* Z releases will also include warning of upcoming breaking changes, whenever possible.

## What this means for you

We recommend running the most recent version. Here are our suggestions for managing updates:

* X changes will require some effort to incorporate.
* Y changes will not require significant effort to incorporate.
* If you have good unit and integration tests, these changes are generally safe to pick up automatically.
* Z changes will not require any changes to your code. Z changes are intended to be picked up automatically.
* Good unit and integration tests are always recommended.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.11.446</version>
<version>1.11.819</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;
import java.util.function.Consumer;

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

String retentionPeriodString = retentionPeriod.get().toString();
long currentTimestamp = System.currentTimeMillis();
CreateQueueRequest superRequest = request.clone()
.withQueueName(queueName)
.withAttributes(attributes);
.withAttributes(attributes)
.addTagsEntry(IDLE_QUEUE_RETENTION_PERIOD_TAG, retentionPeriodString)
.addTagsEntry(LAST_HEARTBEAT_TIMESTAMP_TAG, String.valueOf(currentTimestamp));

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

String retentionPeriodString = retentionPeriod.get().toString();
amazonSqsToBeExtended.tagQueue(queueUrl,
Collections.singletonMap(IDLE_QUEUE_RETENTION_PERIOD_TAG, retentionPeriodString));

// TODO-RS: Filter more carefully to all attributes valid for createQueue
List<String> attributeNames = Arrays.asList(QueueAttributeName.ReceiveMessageWaitTimeSeconds.toString(),
QueueAttributeName.VisibilityTimeout.toString());
Expand All @@ -210,8 +206,9 @@ public CreateQueueResult createQueue(CreateQueueRequest request) {
QueueMetadata metadata = new QueueMetadata(queueName, queueUrl, createdAttributes);
queues.put(queueUrl, metadata);

metadata.heartbeater = executor.scheduleAtFixedRate(() -> heartbeatToQueue(queueUrl),
0, heartbeatIntervalSeconds, TimeUnit.SECONDS);
long initialDelay = ThreadLocalRandom.current().nextLong(heartbeatIntervalSeconds);
metadata.heartbeater = executor.scheduleAtFixedRate(() -> heartbeatToQueue(queueUrl),
initialDelay, heartbeatIntervalSeconds, TimeUnit.SECONDS);

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public void sendMessageRequestCopyWithExtraAttributes() throws IllegalAccessExce
.withDelaySeconds(5)
.withMessageAttributes(Collections.emptyMap())
.withMessageDeduplicationId("dedup")
.withMessageGroupId("groupId");
.withMessageGroupId("groupId")
.withMessageSystemAttributes(Collections.emptyMap());

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

CreateQueueRequest createQueueRequest = new CreateQueueRequest()
.withQueueName("queueName")
.withAttributes(Collections.emptyMap());
.withAttributes(Collections.emptyMap())
.withTags(Collections.emptyMap());

CreateQueueRequest createQueueRequestCopy =
SQSQueueUtils.copyWithExtraAttributes(createQueueRequest, Collections.emptyMap());
Expand Down

0 comments on commit 9a6d210

Please sign in to comment.