Distributed PubSub and Presence platform for the Phoenix Framework http://www.phoenixframework.org/
Find a file
2026-02-06 00:26:14 +01:00
.github/workflows Use :peer for cluster tests and bump Elixir version (#207) 2026-02-06 00:26:14 +01:00
lib/phoenix Add unsubscribe function that matches on metadata (#206) 2026-02-05 22:54:30 +01:00
script Minor fixes to specs and bench scripts (#193) 2024-12-30 10:06:58 +01:00
test Use :peer for cluster tests and bump Elixir version (#207) 2026-02-06 00:26:14 +01:00
.gitignore Port PubSub to Registry 2019-06-26 14:11:51 +02:00
CHANGELOG.md Release v2.2.0 2025-10-22 19:13:39 +02:00
LICENSE.md Pull in PubSub 2016-01-26 13:58:32 -05:00
mix.exs Use :peer for cluster tests and bump Elixir version (#207) 2026-02-06 00:26:14 +01:00
mix.lock Release v2.2.0 2025-10-22 19:13:39 +02:00
README.md github actions 2024-07-11 16:37:11 +02:00

Phoenix.PubSub

Distributed PubSub and Presence platform for the Phoenix Framework

Build Status

Usage

Add phoenix_pubsub to your list of dependencies in mix.exs:

def deps do
  [{:phoenix_pubsub, "~> 2.0"}]
end

Then start your PubSub instance:

defmodule MyApp do
  use Application

  def start(_type, _args) do
    children = [
      {Phoenix.PubSub, name: MyApp.PubSub}
    ]

    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

Now broadcast and subscribe:

Phoenix.PubSub.subscribe(MyApp.PubSub, "user:123")
Phoenix.PubSub.broadcast(MyApp.PubSub, "user:123", :hello_world)

Testing

Testing by default spawns nodes internally for distributed tests. To run tests that do not require clustering, exclude the clustered tag:

$ mix test --exclude clustered

If you have issues running the clustered tests try running:

$ epmd -daemon

before running the tests.