View Source ebus_ps (ebus v0.3.0)

This is an Erlang clone of the original Phoenix.PubSub module. Copyright (c) 2014 Chris McCord

Link to this section Summary

Functions

Broadcasts message on given topic.
Broadcasts message to all but FromPid on given topic.
Returns the topic list. This is an expensive and private operation. DO NOT USE IT IN PROD.

Subscribes the pid to the PubSub adapter's topic.

Returns a set of subscribers pids for the given topic.

Unsubscribes the pid from the PubSub adapter's topic.

Link to this section Types

Link to this section Functions

Link to this function

broadcast(Server, Topic, Msg)

View Source
-spec broadcast(atom(), binary(), term()) -> ok | {error, term()}.
Broadcasts message on given topic.
Link to this function

broadcast_from(Server, FromPid, Topic, Msg)

View Source
-spec broadcast_from(atom(), pid(), binary(), term()) -> ok | {error, term()}.
Broadcasts message to all but FromPid on given topic.
-spec list(atom()) -> [binary()].
Returns the topic list. This is an expensive and private operation. DO NOT USE IT IN PROD.
Link to this function

subscribe(Server, Pid, Topic)

View Source

Equivalent to subscribe(Server, Pid, Topic, []).

Link to this function

subscribe(Server, Pid, Topic, Opts)

View Source
-spec subscribe(atom(), pid(), binary(), options()) -> ok | {error, term()}.

Subscribes the pid to the PubSub adapter's topic.

  • Server: The Pid registered name of the server.
  • Pid: The subscriber pid to receive pubsub messages.
  • Topic: The topic to subscribe to, ie: "users:123".
  • Opts: The optional list of options. See below.
Options:
  • link: links the subscriber to the pubsub adapter.
  • fastlane: Provides a fastlane path for the broadcasts for broadcast() events. The fastlane process is notified of a cached message instead of the normal subscriber. Fastlane handlers must implement fastlane/1 callbacks which accepts a broadcast() struct and returns a fastlaned format for the handler. For example:

  •       ebus_ps:subscribe(
            my_pubsub_server, self(), <<"topic1">>,
            [{fastlane, {FastPid, my_serializer, [<<"event1">>]}).`
Link to this function

subscribers(Server, Topic)

View Source
-spec subscribers(atom(), binary()) -> [pid()].

Returns a set of subscribers pids for the given topic.

  • Server: The registered server name or pid.
  • Topic: The string topic, for example <<"users:123">>.

Example:

  > subscribers(pubsub_server, <<"foo">>).
  [<0.48.0>, <0.49.0>]
Link to this function

unsubscribe(Server, Pid, Topic)

View Source
-spec unsubscribe(atom(), pid(), binary()) -> ok | {error, term()}.
Unsubscribes the pid from the PubSub adapter's topic.