https://github.com/phoenixframework/phoenix_pubsub
Distributed PubSub and Presence platform for the Phoenix Framework
https://github.com/phoenixframework/phoenix_pubsub
Last synced: 5 months ago
JSON representation
Distributed PubSub and Presence platform for the Phoenix Framework
- Host: GitHub
- URL: https://github.com/phoenixframework/phoenix_pubsub
- Owner: phoenixframework
- License: mit
- Created: 2015-11-10T13:51:07.000Z (about 10 years ago)
- Default Branch: main
- Last Pushed: 2024-10-09T19:46:30.000Z (about 1 year ago)
- Last Synced: 2024-10-29T21:59:47.536Z (about 1 year ago)
- Language: Elixir
- Homepage: http://www.phoenixframework.org/
- Size: 379 KB
- Stars: 650
- Watchers: 38
- Forks: 123
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Phoenix.PubSub
> Distributed PubSub and Presence platform for the Phoenix Framework
[](https://github.com/phoenixframework/phoenix_pubsub/actions/workflows/ci.yml)
## Usage
Add `phoenix_pubsub` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:phoenix_pubsub, "~> 2.0"}]
end
```
Then start your PubSub instance:
```elixir
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:
```elixir
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:
```shell
$ mix test --exclude clustered
```
If you have issues running the clustered tests try running:
```shell
$ epmd -daemon
```
before running the tests.