MQTT v0.3.3 MQTT.Server behaviour View Source

A behaviour module for implementing an MQTT "broker".

Link to this section Summary

Types

The init parameters, received from the newly connected client

The reason for rejecting a connection

Functions

See :mqtt_server.enter_loop/3.

See :mqtt_server.stop/1.

See :mqtt_server.stop/3.

Link to this section Types

Link to this type

action()

View Source
action() ::
  {:publish, topic :: String.t(), message :: iodata()}
  | {:publish, topic :: String.t(), message :: iodata(),
     %{optional(:qos) => :mqtt_packet.qos(), optional(:retain) => boolean()}}
  | {:reply, :gen_statem.from(), term()}
Link to this type

init_parameters()

View Source
init_parameters() :: %{
  :protocol => String.t(),
  :clean_session => boolean(),
  :client_id => String.t(),
  optional(:username) => String.t(),
  optional(:password) => String.t(),
  optional(:last_will) => %{
    topic: iodata(),
    message: iodata(),
    qos: :mqtt_packet.qos(),
    retain: boolean()
  }
}

The init parameters, received from the newly connected client

Link to this type

init_stop_reason()

View Source
init_stop_reason() ::
  :identifier_rejected
  | :server_unavailable
  | :bad_username_or_password
  | :not_authorized
  | 6..255

The reason for rejecting a connection

Link to this section Functions

Link to this function

enter_loop(module, args, transport)

View Source

See :mqtt_server.enter_loop/3.

See :mqtt_server.stop/1.

Link to this function

stop(pid, reason, timeout)

View Source

See :mqtt_server.stop/3.

Link to this section Callbacks

Link to this callback

code_change(old_vsn, state, extra)

View Source
code_change(old_vsn, state :: any(), extra :: term()) ::
  {:ok, new_state :: any()} | {:error, reason :: term()}
when old_vsn: term() | {:down, term()}
Link to this callback

handle_call(call, from, state)

View Source
handle_call(call :: any(), from :: :gen_statem.from(), state) ::
  {:ok, state} | {:ok, state, action() | [action()]} | {:stop, reason :: term()}
when state: any()
Link to this callback

handle_cast(cast, state)

View Source
handle_cast(cast :: any(), state) ::
  {:ok, state} | {:ok, state, action() | [action()]} | {:stop, reason :: term()}
when state: any()
Link to this callback

handle_info(info, state)

View Source
handle_info(info :: any(), state) ::
  {:ok, state} | {:ok, state, action() | [action()]} | {:stop, reason :: term()}
when state: any()
Link to this callback

handle_publish(topic, message, opts, state)

View Source
handle_publish(topic :: String.t(), message :: binary(), opts :: map(), state) ::
  {:ok, state} | {:ok, state, action() | [action()]} | {:stop, reason :: term()}
when state: any()
Link to this callback

handle_subscribe(topic, qos, state)

View Source
handle_subscribe(topic :: String.t(), qos :: :mqtt_packet.qos(), state) ::
  {:ok, :mqtt_packet.qos() | :failed, state}
  | {:ok, :mqtt_packet.qos() | :failed, state, action() | [action()]}
  | {:stop, reason :: term()}
when state: any()
Link to this callback

handle_unsubscribe(topic, state)

View Source
handle_unsubscribe(topic :: binary(), state) ::
  {:ok, state} | {:ok, state, action() | [action()]} | {:stop, reason :: term()}
when state: any()
Link to this callback

init(args, params)

View Source
init(args :: any(), params :: init_parameters()) ::
  {:ok, state} | {:stop, reason :: init_stop_reason()}
when state: any()
Link to this callback

terminate(arg1, state)

View Source
terminate(:normal | :shutdown | {:shutdown, term()} | term(), state) :: any()
when state: any()