Skip to content

Commit

Permalink
allows set queue content-based deduplication (#250)
Browse files Browse the repository at this point in the history
* allows set queue content-based deduplication

* fixed codenarc
  • Loading branch information
musketyr authored Jun 27, 2024
1 parent 7d1ef41 commit b18fe6a
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 13 deletions.
13 changes: 7 additions & 6 deletions docs/guide/src/docs/asciidoc/sqs.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ include::{root-dir}/subprojects/micronaut-aws-sdk-test/src/test/resources/applic
<3> Whether to first fetch all queues and set up queue to url cache first time the service is prompted for the queue URL (default `false`)
<4> You can specify the default topic for https://agorapulse.github.io/micronaut-aws-sdk/api/com/agorapulse/micronaut/aws/sqs/SimpleQueueService.html[SimpleQueueService] and `@QueueClient`
<5> Whether the newly created queues are supposed to be https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-queues.html[FIFO queues] (default `false`)
<6> The length of time, in seconds, for which the delivery of all messages in the queue is delayed. Valid values: An integer from `0` to `900` (15 minutes). Default: `0`.
<7> The length of time, in seconds, for which Amazon SQS retains a message. Valid values: An integer representing seconds, from `60` (1 minute) to `1,209,600` (14 days). Default: `345,600` (4 days).
<8> The limit of how many bytes a message can contain before Amazon SQS rejects it. Valid values: An integer from `1,024` bytes (1 KiB) up to `262,144` bytes (256 KiB). Default: `262,144` (256 KiB).
<9> The visibility timeout for the queue, in seconds. Valid values: an integer from `0` to `43,200` (12 hours). Default: `30`.
<10> You can define multiple configurations
<11> Each of the configuration can be access using `@Named('test') SimpleNotificationService` qualifier, or you can define the configuration as `value` of `@NotificationClient('test')`
<6> Enable content based deduplication for FIFO queues (default `false`)
<7> The length of time, in seconds, for which the delivery of all messages in the queue is delayed. Valid values: An integer from `0` to `900` (15 minutes). Default: `0`.
<8> The length of time, in seconds, for which Amazon SQS retains a message. Valid values: An integer representing seconds, from `60` (1 minute) to `1,209,600` (14 days). Default: `345,600` (4 days).
<9> The limit of how many bytes a message can contain before Amazon SQS rejects it. Valid values: An integer from `1,024` bytes (1 KiB) up to `262,144` bytes (256 KiB). Default: `262,144` (256 KiB).
<10> The visibility timeout for the queue, in seconds. Valid values: an integer from `0` to `43,200` (12 hours). Default: `30`.
<11> You can define multiple configurations
<12> Each of the configuration can be access using `@Named('test') SimpleNotificationService` qualifier, or you can define the configuration as `value` of `@NotificationClient('test')`

==== Publishing with `@QueueClient`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public String createQueue(QueueConfiguration configuration) {
attributes.put(QueueAttributeName.FIFO_QUEUE, Boolean.TRUE.toString());
}

if (configuration.getContentBasedDeduplication()) {
attributes.put(QueueAttributeName.CONTENT_BASED_DEDUPLICATION, Boolean.TRUE.toString());
}

if (!attributes.isEmpty()) {
createQueueRequest.attributes(attributes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public QueueConfiguration withFifo(boolean fifo) {
return this;
}

public QueueConfiguration withContentBasedDeduplication(boolean contentBasedDeduplication) {
this.contentBasedDeduplication = contentBasedDeduplication;
return this;
}

public QueueConfiguration withDelaySeconds(Integer delaySeconds) {
this.delaySeconds = delaySeconds;
return this;
Expand All @@ -57,6 +62,7 @@ public QueueConfiguration copy() {
return new QueueConfiguration()
.withQueue(queue)
.withFifo(fifo)
.withContentBasedDeduplication(contentBasedDeduplication)
.withDelaySeconds(delaySeconds)
.withMessageRetentionPeriod(messageRetentionPeriod)
.withMaximumMessageSize(maximumMessageSize)
Expand All @@ -71,6 +77,18 @@ public void setQueue(String queue) {
this.queue = queue;
}

public boolean getContentBasedDeduplication() {
return contentBasedDeduplication;
}

public boolean isContentBasedDeduplication() {
return contentBasedDeduplication;
}

public void setContentBasedDeduplication(boolean contentBasedDeduplication) {
this.contentBasedDeduplication = contentBasedDeduplication;
}

public boolean getFifo() {
return fifo;
}
Expand Down Expand Up @@ -125,6 +143,7 @@ public void setTags(Map<String, String> tags) {

private String queue = "";
private boolean fifo;
private boolean contentBasedDeduplication;

@Min(0L)
@Max(900L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ class DefaultSimpleQueueService implements SimpleQueueService {
createQueueRequest.attributes['VisibilityTimeout'] = configuration.visibilityTimeout.toString()
}
if (configuration.fifo || configuration.queue.endsWith('.fifo')) {
createQueueRequest.attributes['FifoQueue'] = 'true'
createQueueRequest.attributes['FifoQueue'] = Boolean.TRUE.toString()
}

if (configuration.contentBasedDeduplication) {
createQueueRequest.attributes['ContentBasedDeduplication'] = Boolean.TRUE.toString()
}

if (configuration.tags) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public QueueConfiguration withFifo(boolean fifo) {
return this;
}

public QueueConfiguration withContentBasedDeduplication(boolean contentBasedDeduplication) {
this.contentBasedDeduplication = contentBasedDeduplication;
return this;
}

public QueueConfiguration withDelaySeconds(Integer delaySeconds) {
this.delaySeconds = delaySeconds;
return this;
Expand All @@ -57,6 +62,7 @@ public QueueConfiguration copy() {
return new QueueConfiguration()
.withQueue(queue)
.withFifo(fifo)
.withContentBasedDeduplication(contentBasedDeduplication)
.withDelaySeconds(delaySeconds)
.withMessageRetentionPeriod(messageRetentionPeriod)
.withMaximumMessageSize(maximumMessageSize)
Expand All @@ -83,6 +89,18 @@ public void setFifo(boolean fifo) {
this.fifo = fifo;
}

public boolean getContentBasedDeduplication() {
return contentBasedDeduplication;
}

public boolean isContentBasedDeduplication() {
return contentBasedDeduplication;
}

public void setContentBasedDeduplication(boolean contentBasedDeduplication) {
this.contentBasedDeduplication = contentBasedDeduplication;
}

public Integer getDelaySeconds() {
return delaySeconds;
}
Expand Down Expand Up @@ -125,6 +143,7 @@ public void setTags(Map<String, String> tags) {

private String queue = "";
private boolean fifo;
private boolean contentBasedDeduplication;

@Min(0L)
@Max(900L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ aws:
# related to default queue
queue: MyQueue # <4>
fifo: true # <5>
delaySeconds: 0 # <6>
messageRetentionPeriod: 345600 # <7>
maximumMessageSize: 262144 # <8>
visibilityTimeout: 30 # <9>
contentBasedDeduplication: true # <6>
delaySeconds: 0 # <7>
messageRetentionPeriod: 345600 # <8>
maximumMessageSize: 262144 # <9>
visibilityTimeout: 30 # <10>

queues: # <10>
test: # <11>
queues: # <11>
test: # <12>
queue: TestQueue

0 comments on commit b18fe6a

Please sign in to comment.