View Source ebus_ps_local (ebus v0.3.0)

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

Link to this section Summary

Functions

Sends a message to all subscribers of a topic.

Returns the topic list for all local shards.

Returns the topic list for the given shard.

Starts the server.

Subscribes the pid to the topic.

Returns a set of subscribers pids for the given topic.

Returns a set of subscribers pids for the given topic and shard.

See also: subscribers/3.

Returns a set of subscribers pids for the given topic and shard with fastlane tuples.

See also: subscribers_by_shard/3.

Returns a list of topics which Pid is subscribed.

Unsubscribes the pid from the topic.

Link to this section Types

-type fastlane() :: {FastlanePid :: pid(), Serializer :: module(), EventIntercepts :: [term()]}.
-type option() :: {link, _} | {fastlane, fastlane()}.
-type options() :: [option()].

Link to this section Functions

Link to this function

broadcast(Server, PoolSize, From, Topic, Msg)

View Source
-spec broadcast(atom(), pos_integer(), pid(), binary(), term()) -> ok.

Sends a message to all subscribers of a topic.

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

Examples:

  > broadcast(pubsub_server, self(), <<"foo">>).
  ok
  > broadcast(pubsub_server, none, <<"bar">>).
  ok
Link to this function

code_change(OldVsn, State, Extra)

View Source
-spec gc_name(atom(), non_neg_integer()) -> atom().
Link to this function

handle_call(Request, From, State)

View Source
Link to this function

handle_cast(Request, State)

View Source
Link to this function

handle_info(Info, State)

View Source
-spec list(atom(), pos_integer()) -> [binary()].

Returns the topic list for all local shards.

This is an expensive operation. DO NOT USE IT IN PROD

Link to this function

list_by_shard(Server, Shard)

View Source
-spec list_by_shard(atom(), non_neg_integer()) -> [binary()].

Returns the topic list for the given shard.

This is an expensive operation. DO NOT USE IT IN PROD

Link to this function

local_name(Server, Shard)

View Source
-spec local_name(atom(), non_neg_integer()) -> atom().
Link to this function

start_link(ServerName, GCName)

View Source
-spec start_link(atom(), atom()) -> gen_server:start_ret().

Starts the server.

  • ServerName: The name to register the server under.
Link to this function

subscribe(Server, PoolSize, Pid, Topic)

View Source

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

Link to this function

subscribe(Server, PoolSize, Pid, Topic, Opts)

View Source
-spec subscribe(atom(), pos_integer(), pid(), binary(), options()) -> ok.

Subscribes the pid to the 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.

Examples:

  > subscribe(pubsub_server, self(), <<"foo">>, []).
  ok
  > subscribe(pubsub_server, self(), <<"foo">>,
      [{fastlane, {FastPid, my_serializer, [<<"event1">>]}]).
  ok
Link to this function

subscribers(Server, PoolSize, Topic)

View Source
-spec subscribers(atom(), pos_integer(), 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">>.

Examples:

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

subscribers_by_shard(Server, Topic, Shard)

View Source
-spec subscribers_by_shard(atom(), binary(), non_neg_integer()) -> [pid()].
Returns a set of subscribers pids for the given topic and shard.

See also: subscribers/3.

Link to this function

subscribers_with_fastlanes(Server, Topic, Shard)

View Source
-spec subscribers_with_fastlanes(atom(), binary(), non_neg_integer()) -> [{pid(), nil | term()}].
Returns a set of subscribers pids for the given topic and shard with fastlane tuples.

See also: subscribers_by_shard/3.

Link to this function

subscription(Server, PoolSize, Pid)

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

Returns a list of topics which Pid is subscribed.

This is an expensive operation. DO NOT USE IT IN PROD

Link to this function

terminate(Reason, State)

View Source
Link to this function

unsubscribe(Server, PoolSize, Pid, Topic)

View Source
-spec unsubscribe(atom(), pos_integer(), pid(), binary()) -> ok.

Unsubscribes the pid from the topic.

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

Example:

  > unsubscribe(pubsub_server, self(), <<"foo">>).
  ok