Skip to content

Commit

Permalink
Allow to skip the dlk check
Browse files Browse the repository at this point in the history
  • Loading branch information
frnmjn committed Dec 5, 2024
1 parent dcf521f commit 97bc2c2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/amqp/helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ defmodule Amqpx.Helper do
Helper functions
"""

require Logger

alias Amqpx.{Exchange, Queue}

@skip_dlk_check Application.compile_env(:amqpx, :skip_dlk_check, false)

def manager_supervisor_configuration(config) do
{Amqpx.Gen.ConnectionManager, %{connection_params: encrypt_password(config)}}
end
Expand Down Expand Up @@ -92,7 +96,17 @@ defmodule Amqpx.Helper do
end

def setup_dead_lettering(_channel, %{queue: dlq, exchange: "", routing_key: bad_dlq}) do
raise "If x-dead-letter-exchange is an empty string, x-dead-letter-routing-key should be '#{dlq}' instead of '#{bad_dlq}'"
case @skip_dlk_check do
false ->
raise "If x-dead-letter-exchange is an empty string, x-dead-letter-routing-key should be '#{dlq}' instead of '#{bad_dlq}'"

true ->
Logger.warn(
"If x-dead-letter-exchange is an empty string, x-dead-letter-routing-key should be '#{dlq}' instead of '#{bad_dlq}'"
)

:ok
end
end

def setup_dead_lettering(channel, %{queue: dlq, exchange: exchange, routing_key: routing_key}) do
Expand Down
26 changes: 26 additions & 0 deletions test/helper_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,32 @@ defmodule HelperTest do
end
end

test "bad configuration with empty dead letter exchange and routing key is not a blocking error if the check is disabled",

Check failure on line 123 in test/helper_test.exs

View workflow job for this annotation

GitHub Actions / ci

test bad configuration with empty dead letter exchange and routing key is not a blocking error if the check is disabled (HelperTest)
meta do
queue_name = rand_name()
routing_key_name = rand_name()
exchange_name = rand_name()

Application.put_env(:amqpx, :skip_dlk_check, true)

:ok =
Helper.declare(meta[:chan], %{
exchanges: [
%{name: exchange_name, opts: [durable: true], routing_keys: [routing_key_name], type: :topic}
],
opts: [
durable: true,
arguments: [
{"x-dead-letter-exchange", :longstr, ""},
{"x-dead-letter-routing-key", :longstr, ""}
]
],
queue: queue_name
})

Application.put_env(:amqpx, :skip_dlk_check, false)
end

defp rand_name do
:crypto.strong_rand_bytes(8) |> Base.encode64()
end
Expand Down

0 comments on commit 97bc2c2

Please sign in to comment.