diff --git a/CHANGELOG.md b/CHANGELOG.md index c986aea..d21faf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,23 @@ -## [3.1.1] (2024-08-16) +## [3.1.2] (2024-08-16) + +### Bug fixes +- Fix missing specification for `ConsumerServer` unique id + +### Internal +- Prefix modules with `Coney.` to avoid conflicts + +## [3.1.1] (2024-08-16) - BROKEN ### Bug fixes - Fix missing `:name` when starting `ConsumerServer` -## [3.1.0] (2024-08-14) +## [3.1.0] (2024-08-14) - BROKEN ### Enhancements - Add `:enabled` config value - `:adapter` config value is now optional and defaults to `Coney.RabbitConnection` -## [3.0.2] (2024-08-12) +## [3.0.2] (2024-08-12) - BROKEN ### Bug fixes - Fix incorrect termination order where the connection to RabbitMQ was closed before the channels. diff --git a/config/config.exs b/config/config.exs index 4da1c06..bbcaa57 100644 --- a/config/config.exs +++ b/config/config.exs @@ -8,7 +8,8 @@ config :coney, timeout: 1000 }, workers: [ - FakeConsumer + Coney.FakeConsumer, + Coney.OtherFakeConsumer ], topology: %{ exchanges: [{:topic, "exchange", durable: false}], diff --git a/config/test.exs b/config/test.exs index f7a9b22..becde76 100644 --- a/config/test.exs +++ b/config/test.exs @@ -1,25 +1 @@ import Config - -config :coney, - topology: %{ - exchanges: [{:topic, "exchange", durable: false}], - queues: %{ - "queue" => %{ - options: [ - durable: false - ], - bindings: [ - [exchange: "exchange", options: [routing_key: "queue"]] - ] - } - } - }, - pool_size: 1, - auto_start: true, - settings: %{ - url: "amqp://guest:guest@localhost:5672", - timeout: 1000 - }, - workers: [ - FakeConsumer - ] diff --git a/lib/coney/consumer_server.ex b/lib/coney/consumer_server.ex index f593159..77f5941 100644 --- a/lib/coney/consumer_server.ex +++ b/lib/coney/consumer_server.ex @@ -10,6 +10,13 @@ defmodule Coney.ConsumerServer do require Logger + def child_spec([consumer]) do + %{ + id: consumer, + start: {__MODULE__, :start_link, [[consumer]]} + } + end + def start_link([consumer]) do GenServer.start_link(__MODULE__, [consumer], name: consumer) end diff --git a/mix.exs b/mix.exs index 63ef22a..e441c3b 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Coney.Mixfile do def project do [ app: :coney, - version: "3.1.1", + version: "3.1.2", elixir: ">= 1.12.0", build_embedded: Mix.env() == :prod, start_permanent: Mix.env() == :prod, diff --git a/test/lib/coney/connection_server_test.exs b/test/lib/coney/connection_server_test.exs index d6e5b91..f66748a 100644 --- a/test/lib/coney/connection_server_test.exs +++ b/test/lib/coney/connection_server_test.exs @@ -58,7 +58,7 @@ defmodule Coney.ConnectionServerTest do # Subscribe a channel assert {:reply, channel_ref, connected_state} = ConnectionServer.handle_call( - {:subscribe, FakeConsumer}, + {:subscribe, Coney.FakeConsumer}, {self(), :erlang.make_ref()}, state ) @@ -91,7 +91,7 @@ defmodule Coney.ConnectionServerTest do # Subscribe a channel assert {:reply, channel_ref, new_state} = ConnectionServer.handle_call( - {:subscribe, FakeConsumer}, + {:subscribe, Coney.FakeConsumer}, {self(), :erlang.make_ref()}, state ) @@ -100,7 +100,7 @@ defmodule Coney.ConnectionServerTest do pid = self() - assert {^pid, FakeConsumer, _} = Map.get(new_state.channels, channel_ref) + assert {^pid, Coney.FakeConsumer, _} = Map.get(new_state.channels, channel_ref) end end end diff --git a/test/lib/coney/consumer/consumer_server_test.exs b/test/lib/coney/consumer/consumer_server_test.exs index f7328e7..8a3acad 100644 --- a/test/lib/coney/consumer/consumer_server_test.exs +++ b/test/lib/coney/consumer/consumer_server_test.exs @@ -4,11 +4,11 @@ defmodule ConsumerServerTest do alias Coney.ConsumerServer setup do - ref = Coney.ConnectionServer.subscribe(FakeConsumer) + ref = Coney.ConnectionServer.subscribe(Coney.FakeConsumer) [ - args: [FakeConsumer], - state: %{consumer: FakeConsumer, tasks: %{}, chan: ref} + args: [Coney.FakeConsumer], + state: %{consumer: Coney.FakeConsumer, tasks: %{}, chan: ref} ] end @@ -46,7 +46,7 @@ defmodule ConsumerServerTest do describe "handle_info/2" do setup do - %{state: %{consumer: FakeConsumer, tasks: Map.new(), chan: :erlang.make_ref()}} + %{state: %{consumer: Coney.FakeConsumer, tasks: Map.new(), chan: :erlang.make_ref()}} end test "demonitors a task once it completes successfully", %{state: state} do diff --git a/test/support/fake_consumer.ex b/test/support/fake_consumer.ex index 6e477d4..50478de 100644 --- a/test/support/fake_consumer.ex +++ b/test/support/fake_consumer.ex @@ -1,4 +1,4 @@ -defmodule FakeConsumer do +defmodule Coney.FakeConsumer do @behaviour Coney.Consumer def connection do diff --git a/test/support/other_fake_consumer.ex b/test/support/other_fake_consumer.ex new file mode 100644 index 0000000..6bc85ac --- /dev/null +++ b/test/support/other_fake_consumer.ex @@ -0,0 +1,28 @@ +defmodule Coney.OtherFakeConsumer do + @behaviour Coney.Consumer + + def connection do + %{ + prefetch_count: 10, + queue: "queue" + } + end + + def parse(payload, _meta) do + payload + end + + def process(payload, _meta) do + case payload do + :ok -> :ok + :reject -> :reject + :reply -> {:reply, :data} + :exception -> raise "Exception happen" + _other -> :ok + end + end + + def error_happened(_exception, _payload, _meta) do + :ok + end +end