Commanded v0.16.0 Commanded.PubSub.PhoenixPubSub View Source

Pub/sub adapter using Phoenix’s distributed pub/sub and presence platform [1].

[1] https://hex.pm/packages/phoenix_pubsub

To use Phoenix pub/sub you must add it as a dependency in your project’s mix.exs file:

defp deps do
  [
    {:phoenix_pubsub, "~> 1.0"}
  ]
end

Fetch mix deps and configure the pubsub settings in your environment config file:

# `config/config.exs`
config :commanded, pubsub: [
  phoenix_pubsub: [
    adapter: Phoenix.PubSub.PG2,
    pool_size: 1
  ]
]

Specify the Phoenix pub/sub adapter you wish to use from:

  • Phoenix.PubSub.PG2 - uses Distributed Elixir, directly exchanging notifications between servers

  • Phoenix.PubSub.Redis - uses Redis to exchange data between servers

Link to this section Summary

Functions

Broadcasts message on given topic

Start the configured Phoenix pub/sub adapter and a presence tracker

List tracked terms and associated PIDs for a given topic

Subscribes the caller to the topic

Track the current process under the given topic, uniquely identified by key

Link to this section Functions

Link to this function broadcast(topic, message) View Source
broadcast(String.t(), term()) :: :ok | {:error, term()}

Broadcasts message on given topic.

Start the configured Phoenix pub/sub adapter and a presence tracker.

Link to this function list(topic) View Source
list(String.t()) :: [{term(), pid()}]

List tracked terms and associated PIDs for a given topic.

Link to this function subscribe(topic) View Source
subscribe(atom()) :: :ok | {:error, term()}

Subscribes the caller to the topic.

Link to this function track(topic, key) View Source
track(String.t(), term()) :: :ok

Track the current process under the given topic, uniquely identified by key.