From 0d9bcbb248e7f14a839206e2ef1297408afeb1bd Mon Sep 17 00:00:00 2001 From: Timothy Vanderaerden Date: Wed, 9 Oct 2024 11:31:51 +0200 Subject: [PATCH 1/2] Fix `delivery_tag` type for `ack/3` and `reject/3` --- lib/clients/adapter.ex | 9 +++++---- lib/clients/fake_rabbitmq.ex | 4 ++-- lib/clients/rabbitmq.ex | 8 ++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/clients/adapter.ex b/lib/clients/adapter.ex index baac58e..b877ae8 100644 --- a/lib/clients/adapter.ex +++ b/lib/clients/adapter.ex @@ -9,14 +9,15 @@ defmodule ExRabbitPool.Clients.Adapter do {:ok, String.t()} | AMQP.Basic.error() @callback cancel_consume(AMQP.Channel.t(), String.t(), keyword) :: {:ok, String.t()} | {:error, AMQP.Basic.error()} - @callback ack(AMQP.Channel.t(), String.t(), keyword()) :: :ok | AMQP.Basic.error() - @callback reject(AMQP.Channel.t(), String.t(), keyword()) :: :ok | AMQP.Basic.error() + @callback ack(AMQP.Channel.t(), AMQP.Basic.delivery_tag(), keyword()) :: + :ok | AMQP.Basic.error() + @callback reject(AMQP.Channel.t(), AMQP.Basic.delivery_tag(), keyword()) :: + :ok | AMQP.Basic.error() @callback declare_queue(AMQP.Channel.t(), AMQP.Basic.queue(), keyword()) :: {:ok, map()} | AMQP.Basic.error() @callback queue_bind(AMQP.Channel.t(), AMQP.Basic.queue(), AMQP.Basic.exchange(), keyword()) :: :ok | AMQP.Basic.error() @callback declare_exchange(AMQP.Channel.t(), AMQP.Basic.exchange(), keyword()) :: :ok | AMQP.Basic.error() - @callback qos(AMQP.Channel.t(), keyword()) :: - :ok | AMQP.Basic.error() + @callback qos(AMQP.Channel.t(), keyword()) :: :ok | AMQP.Basic.error() end diff --git a/lib/clients/fake_rabbitmq.ex b/lib/clients/fake_rabbitmq.ex index be1a533..1f76787 100644 --- a/lib/clients/fake_rabbitmq.ex +++ b/lib/clients/fake_rabbitmq.ex @@ -24,12 +24,12 @@ defmodule ExRabbitPool.FakeRabbitMQ do end @impl true - def ack(_channel, _tag, _options \\ []) do + def ack(_channel, _delivery_tag, _options \\ []) do :ok end @impl true - def reject(_channel, _tag, _options \\ []) do + def reject(_channel, _delivery_tag, _options \\ []) do :ok end diff --git a/lib/clients/rabbitmq.ex b/lib/clients/rabbitmq.ex index b4c7f17..6470963 100644 --- a/lib/clients/rabbitmq.ex +++ b/lib/clients/rabbitmq.ex @@ -21,13 +21,13 @@ defmodule ExRabbitPool.RabbitMQ do end @impl true - def ack(%Channel{} = channel, tag, options \\ []) do - Basic.ack(channel, tag, options) + def ack(%Channel{} = channel, delivery_tag, options \\ []) do + Basic.ack(channel, delivery_tag, options) end @impl true - def reject(%Channel{} = channel, tag, options \\ []) do - Basic.reject(channel, tag, options) + def reject(%Channel{} = channel, delivery_tag, options \\ []) do + Basic.reject(channel, delivery_tag, options) end @impl true From 4ee92c8751bf8effcd4a80eed21ce0eb5f7f86eb Mon Sep 17 00:00:00 2001 From: Timothy Vanderaerden Date: Wed, 9 Oct 2024 13:32:03 +0200 Subject: [PATCH 2/2] Follow `basic_consume_ok/2` and `basic_deliver/3` contract According to the callback `basic_consume_ok/2` and `basic_deliver/3` expect `:ok` or `{:stop, reason :: any()}`. However they both contain a case clause which can never be invoked since other clauses in that case matches the contract. --- lib/consumer.ex | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/consumer.ex b/lib/consumer.ex index b7ee6fd..75ceb08 100644 --- a/lib/consumer.ex +++ b/lib/consumer.ex @@ -116,9 +116,6 @@ defmodule ExRabbitPool.Consumer do {:stop, reason} -> {:stop, reason, state} - - _ -> - {:noreply, state} end end @@ -133,9 +130,6 @@ defmodule ExRabbitPool.Consumer do {:stop, reason} -> {:stop, reason, state} - - _ -> - {:noreply, state} end end