sbroker_user (sbroker v1.1.1)
This module provides helpers for managing sbroker
processes that are automatically started in the sbroker
supervision tree.
brokers
can be automatically started when the sbroker
application starts by setting the sbroker
application env brokers
. It is a list of broker names and specifications, of the form: [{Name :: sbroker:name(),
Spec :: {AskQueueSpec :: sbroker:handler_spec(),
AskRQueueSpec :: sbroker:handler_spec(),
[MeterSpec :: sbroker:handler_spec()]}}]
Name
is the name of the broker and each broker will be registered using its name, e.g. {local, my_broker}
. Spec
is the specification for the sbroker
, which is equivalent to returning {ok, Spec}
from the init/1
callback: AskQueueSpec
is the ask
queue spec, AskRQueueSpec
is the ask_r
queue spec and MeterSpec
is a meter spec.
sbroker
application allows multiple applications, or parts of the same supervision tree, to access a sbroker
even if their counterparty crashes. It also allows either party to be started first and await the other using the sbroker
queues.
Link to this section Summary
Functions
Call sbroker:change_config/1
on all brokers started in the sbroker
application.
Delete a broker with name, Name
.
Restart a broker with name, Name
.
Starts a broker with name, Name
.
Terminate a broker with name, Name
.
List user brokers started in the sbroker
application.
Link to this section Functions
change_config()
Specs
change_config() -> [{Name, Reason}] when Name :: sbroker:name(), Reason :: term().
Call sbroker:change_config/1
on all brokers started in the sbroker
application.
This function can be used to reconfigure all brokers that are already started after the sbroker
application env brokers
is changed.
Name
is the sbroker:name()
of the broker and Reason
is the reason.
delete(Name)
Specs
delete(Name) -> ok | {error, Reason} when Name :: sbroker:name(), Reason :: running | restarting | not_found.
Delete a broker with name, Name
.
The broker is deleted in the sbroker
application's supervision tree using Brokers are automatically started when the sbroker
is started, and might be restarted if the entry remains in the sbroker
application env brokers
, so this function should only be required to delete a broker after it has removed from brokers
.
ok
on successfully deleting the regulator, otherwise {error, Reason}
where Reason
is reason for the error.
restart(Name)
Specs
restart(Name) -> {ok, Pid} | {error, Reason} when Name :: sbroker:name(), Pid :: pid() | undefined, Reason :: term().
Restart a broker with name, Name
.
The broker is restarted in the sbroker
application's supervision tree using configuration from the sbroker
application env brokers
. Brokers are automatically started when the sbroker
is started so this function should only be required if a broker is terminated.
{ok, Pid}
on starting the broker, where Pid
is the pid()
of the broker, {ok, undefined}
if a configuration for Name
does not exist in brokers
or {error, Reason}
if the broker fails to start with reason Reason
.
start(Name)
Specs
start(Name) -> {ok, Pid} | {error, Reason} when Name :: sbroker:name(), Pid :: pid() | undefined, Reason :: term().
Starts a broker with name, Name
.
The broker is started in the sbroker
application's supervision tree using configuration from the sbroker
application env brokers
. Brokers are automatically started when the sbroker
application is started so this function should only be required if a broker is added to the configuration.
{ok, Pid}
on starting the broker, where Pid
is the pid()
of the broker, {ok, undefined}
if a configuration for Name
does not exist in brokers
or {error, Reason}
if the broker fails to start with reason Reason
.
terminate(Name)
Specs
terminate(Name) -> ok | {error, not_found} when Name :: sbroker:name().
Terminate a broker with name, Name
.
The broker is terminated in the sbroker
application's supervision tree. Brokers are automatically started when the sbroker
is started, and might be restarted if the entry remains in the sbroker
application env brokers
, so this function should only be required to terminate a broker after it has been removed from brokers
.
ok
once the broker is terminated, otherwise {error, not_found}
.
which_brokers()
Specs
which_brokers() -> [{Name, Pid, Type, Modules}] when Name :: sbroker:name(), Pid :: undefined | pid(), Type :: worker, Modules :: dynamic.
List user brokers started in the sbroker
application.
Name
is the sbroker:name()
of the broker, Pid
is the pid()
or undefined
, Type
is worker
and Modules
is dynamic
.