Registry

Announcement

  children = [
    # ...
    {Registry, keys: :unique, name: Registry.EventGenServer, partitions: System.schedulers_online()}

Partitions apparently makes it more concurrent if needed(Note that the registry uses one ETS table plus two ETS tables per partition.)

Usage

Registering

start_link with the name to register in Registry

  def start_link({cname, event_id, subevent_id, group_id}) do
    name = {:via, Registry, {EventGenServer, cname}}

    # seems to be :ok to return pid to supervisor
    case GenServer.start_link(__MODULE__, {cname, event_id, subevent_id, group_id}, name: name) do
      {:ok, pid} -> {:ok, pid}
      {:error, {:already_started, pid}} -> {:ok, pid}
    end
  end

Other

Lookup

Dispatch

Pubsub

Registries can also be used to implement a local, non-distributed, scalable PubSub by relying on the dispatch/3

Can also use Genserver.call/2 with the name to send direct message

Last updated