EmqttFailover.Connection (EmqttFailover v0.3.2)
Wraps an :emqtt client.
Summary
Functions
Returns a specification to start this module under a supervisor.
Publishes a message to the broker.
Publishes a message to the broker without waiting for a reply.
Returns the current connection status, along with the configuration for the connection.
Gracefully stops the connection.
Types
backoff()
@type backoff() :: non_neg_integer() | {non_neg_integer(), non_neg_integer()} | {non_neg_integer(), non_neg_integer(), :normal | :jitter}
config()
@type config() :: EmqttFailover.Config.t() | String.t()
handler()
param()
@type param() :: {:backoff, backoff()} | {:configs, Enumerable.t(config()) | config()} | {:client_id, binary()} | {:handler, handler()} | GenServer.option()
status()
@type status() :: :not_connected | :connected
Functions
child_spec(init_arg)
Returns a specification to start this module under a supervisor.
See Supervisor
.
publish(server, message, timeout \\ :infinity)
@spec publish(GenServer.server(), EmqttFailover.Message.t(), timeout()) :: :ok | {:error, term()}
Publishes a message to the broker.
For more on the message, see EmqttFailover.Message
.
For qos: 0
messages, this always returns :ok
If the message has qos: 1
or qos: 2
and the server is not connected or the message is not acknowledged, this will return an error.
publish_async(server, message)
@spec publish_async(GenServer.server(), EmqttFailover.Message.t()) :: :ok
Publishes a message to the broker without waiting for a reply.
For more on the message, see EmqttFailover.Message
.
start_link(config_or_opts)
@spec start_link(config() | [param()]) :: GenServer.on_start()
Start a Elixir.EmqttFailover.Connection
.
Required parameters:
configs
: an Enumerable of URLs orEmqttFailover.Config
structs. These will be tried in order.
Optional parameters:
backoff
: either a single number of milliseconds to wait after a connection failure, a tuple{start, max}
wherestart
andmax
are the initial and maximum number of milliseconds to wait, or{start, max, :jitter}
to add some random jitter to the specific reconnection times. Note: this backoff timeout will only be used after all the failover connections have been tried.client_id
: a binary to be used as the identifier for this clienthandler
: either a module implementingEmqttFailover.ConnectionHandler
or a tuple{module, init_args}
whereinit_args
are passed to the module'sinit/1
function.
status(server)
@spec status(GenServer.server()) :: {status(), EmqttFailover.Config.t()}
Returns the current connection status, along with the configuration for the connection.
If the status
is :not_connected
, the config that is returned is the next one that will be tried.
stop(server, timeout \\ :infinity)
@spec stop(GenServer.server(), timeout()) :: :ok
Gracefully stops the connection.