From 97bc2c213b48cd3dac90014424b9876dc5003234 Mon Sep 17 00:00:00 2001 From: Emilio Junior Francischetti Date: Thu, 5 Dec 2024 15:51:02 +0100 Subject: [PATCH] Allow to skip the dlk check --- lib/amqp/helper.ex | 16 +++++++++++++++- test/helper_test.exs | 26 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/amqp/helper.ex b/lib/amqp/helper.ex index adf8592..f76e267 100644 --- a/lib/amqp/helper.ex +++ b/lib/amqp/helper.ex @@ -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 @@ -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 diff --git a/test/helper_test.exs b/test/helper_test.exs index e59e85b..37653bd 100644 --- a/test/helper_test.exs +++ b/test/helper_test.exs @@ -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", + 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