ebus` interface. This module also works as a wrapper on top
of `ebus_ps
module.
Behaviours: application.
See also: ebus_ps.
ebus` interface. This module also works as a wrapper on top
of `ebus_ps
module.
dispatch_fun() = fun(([term()]) -> term())
Receives as argument the subscribers list. Then it should choose one subscriber from the given list and return it.
dispatch_opt() = {scope, local | global} | {dispatch_fun, dispatch_fun()}
Available dispatch options.
dispatch_opts() = [dispatch_opt()]
Dispatch options.
handler() = pid()
options() = ebus_ps_local:options()
sub/4
options.
topic() = iodata()
default_ps_server/0 | Returns default ebus server name: ebus_ps . |
dispatch/2 | Equivalent to dispatch(Topic, Message, []). |
dispatch/3 | Equivalent to dispatch(server(), Topic, Message, Opts). |
dispatch/4 |
Sends a message only to one subscriber handler of the Topic . |
local_subscribers/1 | Equivalent to local_subscribers(server(), Topic). |
local_subscribers/2 |
Same as subscribers/2 but only local subscribers handlers for the
given Topic are returned. |
local_topics/0 | Equivalent to local_topics(server()). |
local_topics/1 |
Same as topics/1 but only local topics are returned. |
pub/2 | Equivalent to pub(server(), Topic, Message). |
pub/3 | Sends a message to all subscribers of a topic. |
pub_from/3 | Equivalent to pub_from(server(), From, Topic, Message). |
pub_from/4 |
Same as pub/3 but message is not sent to FromHandler . |
server/0 | Returns the registered ebus server name. |
start/0 | Starts ebus application. |
stop/0 | Stops ebus application. |
sub/2 | Equivalent to sub(server(), Handler, Topic). |
sub/3 | Equivalent to sub(Server, Handler, Topic, []). |
sub/4 |
Subscribes the Handler given Topic . |
subscribers/1 | Equivalent to subscribers(server(), Topic). |
subscribers/2 |
Returns a set of all subscribers handlers (local and global)
for the given Topic . |
topics/0 | Equivalent to topics(server()). |
topics/1 | Returns the list of all topics (local and global) in use. |
unsub/2 | Equivalent to unsub(server(), Handler, Topic). |
unsub/3 |
Unsubscribes the given Handler from the Topic . |
default_ps_server() -> ebus_ps
Returns default ebus
server name: ebus_ps
.
dispatch(Topic, Message) -> any()
Equivalent to dispatch(Topic, Message, []).
dispatch(Topic, Message, Opts) -> any()
Equivalent to dispatch(server(), Topic, Message, Opts).
dispatch(Server::atom(), Topic::topic(), Message::term(), Opts::dispatch_opts()) -> ok
Sends a message only to one subscriber handler of the Topic
.
Server
: The registered server name or pid.Topic
: The string topic, for example <<"users:123">>
.Message
: Any erlang term.Opts
: The optional list of options. See below.{scope, local | global}
: define if the message must be delivered
to a local or global (any) process. Default is local
.{dispatch_fun, dispatch_fun()}
: allows to pass a function to
choose a subscriber from the current subscribers handlers to a topic.Examples:
> ebus:dispatch("bar", #{topic => "foo", payload => "hi"}). ok > ebus:dispatch("bar", #{topic => "foo", payload => "hi"}, []). ok > ebus:dispatch(ebus_ps, "bar", "my message", [{scope, global}, {dispatch_fun, fun([H | _]) -> H end}]). ok
local_subscribers(Topic) -> any()
Equivalent to local_subscribers(server(), Topic).
local_subscribers(Server::atom(), Topic::topic()) -> [pid()]
Same as subscribers/2
but only local subscribers handlers for the
given Topic
are returned.
Example:
> ebus:local_subscribers(ebus_ps, <<"foo">>). [<0.48.0>, <0.49.0>]
local_topics() -> any()
Equivalent to local_topics(server()).
local_topics(Server::atom()) -> [binary()]
Same as topics/1
but only local topics are returned.
Example:
> ebus:local_topics(). [<<"foo">>, <<"bar">>] > ebus:local_topics(ebus_ps). [<<"foo">>, <<"bar">>]
pub(Topic, Message) -> any()
Equivalent to pub(server(), Topic, Message).
pub(Server::atom(), Topic::topic(), Message::term()) -> ok | {error, term()}
Sends a message to all subscribers of a topic.
Server
: The registered server name or pid.Topic
: The string topic, for example <<"users:123">>
.Message
: Any erlang term.Examples:
> ebus:pub("bar", #{topic => "foo", payload => "hi"}). ok > ebus:pub(ebus_ps, "bar", #{topic => "foo", payload => "hi"}). ok
pub_from(From, Topic, Message) -> any()
Equivalent to pub_from(server(), From, Topic, Message).
pub_from(Server::atom(), FromHandler::handler(), Topic::topic(), Message::term()) -> ok | {error, term()}
Same as pub/3
but message is not sent to FromHandler
.
Examples:
> ebus:pub_from(self(), "foo", <<"message">>). ok > ebus:pub_from(ebus_ps, self(), "foo", <<"message">>). ok
server() -> atom()
Returns the registered ebus
server name.
start() -> {ok, term()} | {error, term()}
Starts ebus
application.
stop() -> ok | {error, term()}
Stops ebus
application.
sub(Handler, Topic) -> any()
Equivalent to sub(server(), Handler, Topic).
sub(Server, Handler, Topic) -> any()
Equivalent to sub(Server, Handler, Topic, []).
Subscribes the Handler
given Topic
.
Server
: The Pid registered name of the server.Handler
: The subscriber pid to receive pubsub messages.Topic
: The topic to subscribe to, ie: "users:123"
.Opts
: The optional list of options. See below.{link, _}
: links the subscriber to the pubsub adapter.{fastlane, ebus_ps_local: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:
> ebus:sub(self(), <<"foo">>). ok > ebus:sub(ebus_ps, self(), <<"foo">>). ok > ebus:sub(ebus_ps, self(), <<"foo">>, []). ok > ebus:sub(ebus_ps, self(), <<"foo">>, [{fastlane, {FastPid, my_serializer, [<<"event1">>]}]). ok
subscribers(Topic) -> any()
Equivalent to subscribers(server(), Topic).
subscribers(Server::atom(), Topic::topic()) -> [pid()]
Returns a set of all subscribers handlers (local and global)
for the given Topic
.
Server
: The registered server name or pid.Topic
: The string topic, for example <<"users:123">>
.Example:
> ebus:subscribers(ebus_ps, <<"foo">>). [<0.48.0>, <0.49.0>]
topics() -> any()
Equivalent to topics(server()).
topics(Server::atom()) -> [binary()]
Returns the list of all topics (local and global) in use. This is an expensive and private operation.
This is an expensive operation. DO NOT USE IT IN PROD
Example:
> ebus:topics(). [<<"foo">>, <<"bar">>] > ebus:topics(ebus_ps). [<<"foo">>, <<"bar">>]
unsub(Handler, Topic) -> any()
Equivalent to unsub(server(), Handler, Topic).
Unsubscribes the given Handler
from the Topic
.
Server
: The registered server name or pid.Handler
: The subscriber pid.Topic
: The string topic, for example <<"users:123">>
.Example:
> ebus:unsub(self(), <<"foo">>). ok > ebus:unsub(ebus_ps, self(), <<"foo">>). ok
Generated by EDoc