Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
Fix options parsing (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorszun committed Apr 27, 2020
1 parent e120328 commit ce87267
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/gen_rmq/consumer/queue_configuration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ defmodule GenRMQ.Consumer.QueueConfiguration do
# This is done in order to be backwards compatible.
# If one day those two keywords are removed from the
# init, then this function can be removed as well.
queue_option_arguments = Keyword.get(option_list, :arguments, [])

word_list
|> remove_keyword(option_list[:arguments], %{name: "x-expires", word: :ttl})
|> remove_keyword(option_list[:arguments], %{name: "x-max-priority", word: :max_priority})
|> remove_keyword(queue_option_arguments, %{name: "x-expires", word: :ttl})
|> remove_keyword(queue_option_arguments, %{name: "x-max-priority", word: :max_priority})
|> Keyword.merge(option_list)
end

defp remove_keyword(word_list, [], _argument), do: word_list

defp remove_keyword(word_list, option_arguments, argument) do
case Enum.find(option_arguments, fn arg -> elem(arg, 0) == argument.name end) do
nil -> word_list
Expand Down
20 changes: 20 additions & 0 deletions test/gen_rmq_consumer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ defmodule GenRMQ.ConsumerTest do
alias TestConsumer.WithFanoutExchange
alias TestConsumer.WithMultiBindingExchange
alias TestConsumer.RedeclaringExistingExchange
alias TestConsumer.WithQueueOptionsWithoutArguments

@connection "amqp://guest:guest@localhost:5672"

Expand Down Expand Up @@ -338,6 +339,25 @@ defmodule GenRMQ.ConsumerTest do
close_connection_and_channels_after_shutdown_test()
end

describe "TestConsumer.WithQueueOptionsWithoutArguments" do
setup do
Agent.start_link(fn -> MapSet.new() end, name: WithQueueOptionsWithoutArguments)
with_test_consumer(WithQueueOptionsWithoutArguments)
end

receive_message_test(WithQueueOptionsWithoutArguments)

reconnect_after_connection_failure_test(WithQueueOptionsWithoutArguments)

terminate_after_queue_deletion_test()

exit_signal_after_queue_deletion_test()

close_connection_and_channels_after_deletion_test()

close_connection_and_channels_after_shutdown_test()
end

describe "Telemetry events" do
setup :attach_telemetry_handlers

Expand Down
31 changes: 31 additions & 0 deletions test/support/test_consumers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,35 @@ defmodule TestConsumer do

def handle_message(_), do: :ok
end

defmodule WithQueueOptionsWithoutArguments do
@moduledoc false
@behaviour GenRMQ.Consumer

def init() do
[
queue: "gen_rmq_in_queue_options_no_args",
queue_options: [durable: true],
exchange: {:topic, "gen_rmq_in_exchange_queue_options_no_args"},
routing_key: "#",
prefetch_count: "10",
connection: "amqp://guest:guest@localhost:5672",
deadletter: false,
]
end

def consumer_tag() do
"TestConsumer.WithQueueOptionsWithoutArguments"
end

def handle_message(%GenRMQ.Message{payload: "\"reject\""} = message) do
GenRMQ.Consumer.reject(message)
end

def handle_message(message) do
payload = Jason.decode!(message.payload)
Agent.update(__MODULE__, &MapSet.put(&1, payload))
GenRMQ.Consumer.ack(message)
end
end
end

0 comments on commit ce87267

Please sign in to comment.