In my lib/myapp/application.ex
file I set up a Registry and I give it the name :myapp_registry
:
def start(_type, _args) do
children = [
# Start the Ecto repository
MyApp.Repo,
# Start the Telemetry supervisor
MyAppWeb.Telemetry,
# Start the PubSub system
{Phoenix.PubSub, name: MyApp.PubSub},
# Start the Endpoint (http/https)
MyAppWeb.Endpoint,
{Registry, [keys: :unique, name: :myapp_registry]},
# , Start a worker by calling: MyApp.Worker.start_link(arg)
# {MyApp.Worker, arg}
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)
end
Then, in another module, when some event happens, I try and see what keys are in my registry:
IO.inspect(Registry.keys(:myapp_registry, self()))
But I get an error:
(ArgumentError) unknown registry: :myapp_registry
So… how do I start a Registry in my Phoenix application supervision tree and give it a name such that I can find and use my Registry later?