Skip to content

Commit

Permalink
feat: add raw_message_delivery option to queue
Browse files Browse the repository at this point in the history
  • Loading branch information
JhoMartins committed Jul 30, 2021
1 parent 8ba8c6b commit 73e5ce7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
8 changes: 6 additions & 2 deletions lib/ex_aws_configurator/queue.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ defmodule ExAwsConfigurator.QueueOptions do
@type queue_options :: [
max_receive_count: integer(),
dead_letter_queue: boolean(),
dead_letter_queue_suffix: binary()
dead_letter_queue_suffix: binary(),
raw_message_delivery: boolean()
]

defstruct max_receive_count: 7, dead_letter_queue: true, dead_letter_queue_suffix: "_failures"
defstruct max_receive_count: 7,
dead_letter_queue: true,
dead_letter_queue_suffix: "_failures",
raw_message_delivery: false
end

defmodule ExAwsConfigurator.Queue do
Expand Down
21 changes: 17 additions & 4 deletions lib/ex_aws_configurator/sqs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ defmodule ExAwsConfigurator.SQS do
alias ExAwsConfigurator.{Queue, Topic}
alias ExAws.{SNS, SQS}

@raw_message_delivery "raw_message_delivery"

@doc """
Create an sqs queue based on ex_aws_configurator configuration, that method do NOT subscribe on any topic
Expand Down Expand Up @@ -100,10 +102,15 @@ defmodule ExAwsConfigurator.SQS do

Logger.info("Subscribe queue #{Queue.full_name(queue)} to topic #{Topic.full_name(topic)}")

topic
|> Topic.arn()
|> SNS.subscribe("sqs", Queue.arn(queue))
|> ExAws.request(region: topic.region)
with {:ok, %{body: %{subscription_arn: subscription_arn}}} = subscription_response <-
topic
|> Topic.arn()
|> SNS.subscribe("sqs", Queue.arn(queue))
|> ExAws.request(region: topic.region) do
if queue.options.raw_message_delivery,
do: set_raw_message_delivery(subscription_arn),
else: subscription_response
end
end

@doc """
Expand Down Expand Up @@ -184,4 +191,10 @@ defmodule ExAwsConfigurator.SQS do
|> SQS.create_queue(attributes, tags)
|> ExAws.request(region: queue.region)
end

defp set_raw_message_delivery(subscription_arn) do
@raw_message_delivery
|> SNS.set_subscription_attributes(true, subscription_arn)
|> ExAws.request()
end
end

0 comments on commit 73e5ce7

Please sign in to comment.