Skip to content

Commit 9f415a1

Browse files
committed
exchange_type: add caches supervisor starting boot step
Previously, the caches supervisor was started as a Mix application. As the application depends on rabbit it was started after its boot procedure completed. This means that when the persistent exchanges are created at rabbit startup, the caches supervisor is not running. As a consequence, the VHost was crashing. Signed-off-by: Matteo Cafasso <[email protected]>
1 parent 4e3dd38 commit 9f415a1

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

lib/rabbit_message_deduplication_exchange.ex

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule RabbitMQ.ExchangeTypeMessageDeduplication do
22
import Record, only: [defrecord: 2, extract: 2]
33

44
require RabbitMQ.Cache
5-
require RabbitMQ.Supervisor
5+
require RabbitMQ.CacheSupervisor
66

77
alias :rabbit_misc, as: RabbitMisc
88
alias :rabbit_router, as: RabbitRouter
@@ -22,6 +22,13 @@ defmodule RabbitMQ.ExchangeTypeMessageDeduplication do
2222
{:requires, :rabbit_registry},
2323
{:enables, :kernel_ready}]}
2424

25+
@rabbit_boot_step {:rabbit_exchange_type_caches_supervisor,
26+
[{:description,
27+
"message deduplication exchange type: supervisor"},
28+
{:mfa, {__MODULE__, :start_caches_supervisor, []}},
29+
{:requires, :rabbit_registry},
30+
{:enables, :kernel_ready}]}
31+
2532
defrecord :exchange, extract(
2633
:exchange, from_lib: "rabbit_common/include/rabbit.hrl")
2734

@@ -34,6 +41,10 @@ defmodule RabbitMQ.ExchangeTypeMessageDeduplication do
3441
defrecord :basic_message, extract(
3542
:basic_message, from_lib: "rabbit_common/include/rabbit.hrl")
3643

44+
def start_caches_supervisor() do
45+
RabbitMQ.CacheSupervisor.start_link()
46+
end
47+
3748
def description() do
3849
[
3950
{:name, <<"x-message-deduplication">>},
@@ -100,13 +111,8 @@ defmodule RabbitMQ.ExchangeTypeMessageDeduplication do
100111
|> rabbitmq_keyfind("x-cache-persistence", "memory")
101112
|> String.to_atom()
102113
options = [size: size, ttl: ttl, persistence: persistence]
103-
specifications = %{id: cache,
104-
start: {RabbitMQ.Cache, :start_link, [cache, options]}}
105114

106-
case RabbitMQ.Supervisor.start_child(specifications) do
107-
{:ok, _} -> :ok
108-
{:error, {:already_started, _}} -> :ok
109-
end
115+
RabbitMQ.CacheSupervisor.start_cache(cache, options)
110116
end
111117

112118
def create(:none, _ex) do
@@ -117,7 +123,8 @@ defmodule RabbitMQ.ExchangeTypeMessageDeduplication do
117123
cache = cache_name(name)
118124

119125
:ok = RabbitMQ.Cache.drop(cache)
120-
cache |> RabbitMQ.Cache.process() |> RabbitMQ.Supervisor.terminate_child()
126+
127+
RabbitMQ.CacheSupervisor.stop_cache(cache)
121128
end
122129

123130
def delete(:none, _ex, _bs) do

0 commit comments

Comments
 (0)