Skip to content

Commit

Permalink
feat: allow content_based_deduplication attributes to be set when cre…
Browse files Browse the repository at this point in the history
…ating a queue
  • Loading branch information
henriquedalvi committed Oct 20, 2021
1 parent ea5818c commit b4c76ff
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/ex_aws_configurator/queue.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
defmodule ExAwsConfigurator.QueueAttributes do
@type t :: ExAws.SQS.queue_attributes()

defstruct delay_seconds: 0,
defstruct content_based_deduplication: false,
delay_seconds: 0,
fifo_queue: false,
maximum_message_size: 262_144,
message_retention_period: 1_209_600,
Expand Down
13 changes: 12 additions & 1 deletion lib/ex_aws_configurator/sqs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ defmodule ExAwsConfigurator.SQS do
Logger.info(~s"""
\n\n Creating queue #{full_name} on #{queue.region}
Attributes:
#{IO.ANSI.green()}>#{IO.ANSI.reset()} content_based_deduplication: #{
queue.attributes.content_based_deduplication
}
#{IO.ANSI.green()}>#{IO.ANSI.reset()} delay_seconds: #{queue.attributes.delay_seconds}
#{IO.ANSI.green()}>#{IO.ANSI.reset()} fifo_queue: #{queue.attributes.fifo_queue}
#{IO.ANSI.green()}>#{IO.ANSI.reset()} maximum_message_size: #{
Expand Down Expand Up @@ -169,7 +172,15 @@ defmodule ExAwsConfigurator.SQS do
full_name = Queue.full_name(queue) <> options.dead_letter_queue_suffix

dead_letter_queue =
struct(queue, %{attributes: struct(attributes, %{redrive_policy: nil, policy: nil})})
struct(queue, %{
attributes:
struct(attributes, %{
content_based_deduplication: attributes.content_based_deduplication,
fifo_queue: attributes.fifo_queue,
redrive_policy: nil,
policy: nil
})
})

create_queue_on_sqs(full_name, dead_letter_queue, tags)

Expand Down
9 changes: 7 additions & 2 deletions test/ex_aws_configurator/sqs_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ defmodule ExAwsConfigurator.SQSTest do
add_queue_to_config(%{queue_min_config: %{}})
add_topic_to_config(build(:topic_config, name: :topic_name))
add_queue_to_config(build(:queue_config, name: :raw_queue, raw_message_delivery: true))
add_queue_to_config(build(:queue_config, name: :fifo_queue, fifo_queue: true))

add_queue_to_config(
build(:queue_config, name: :fifo_queue, content_based_deduplication: true, fifo_queue: true)
)

add_queue_to_config(
build(:queue_config, name: :without_failures_queue, dead_letter_queue: false)
Expand Down Expand Up @@ -42,7 +45,9 @@ defmodule ExAwsConfigurator.SQSTest do

test "create a fifo queue" do
assert {:ok, %{status_code: 200}} = SQS.create_queue(:fifo_queue)
assert %{attributes: %{fifo_queue: true}} = ExAwsConfigurator.get_queue(:fifo_queue)

assert %{attributes: %{content_based_deduplication: true, fifo_queue: true}} =
ExAwsConfigurator.get_queue(:fifo_queue)
end

test "raise when tries to create a queue without configuration" do
Expand Down
2 changes: 2 additions & 0 deletions test/support/config_factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ defmodule ExAwsConfigurator.Factory.Config do
raw_message_delivery = Map.get(attrs, :raw_message_delivery, false)
dead_letter_queue = Map.get(attrs, :dead_letter_queue, true)
fifo_queue = Map.get(attrs, :fifo_queue, false)
content_based_deduplication = Map.get(attrs, :content_based_deduplication, false)

queue_config =
%{
Expand All @@ -27,6 +28,7 @@ defmodule ExAwsConfigurator.Factory.Config do
dead_letter_queue: dead_letter_queue
],
attributes: [
content_based_deduplication: content_based_deduplication,
fifo_queue: fifo_queue
],
topics: []
Expand Down

0 comments on commit b4c76ff

Please sign in to comment.