ExMqtt.Handler behaviour (ex_mqtt_uv v0.1.0)

Copy Markdown View Source

Callback behaviour for handling incoming MQTT messages, MQTT 5.0 AUTH challenges, and connection lifecycle events.

If you do not provide a :handler module in ExMqtt.start_link/1, events are sent as Erlang messages to the :owner process (defaults to the caller of start_link/1):

  • {:ex_mqtt, client_pid, {:publish, %ExMqtt.Protocol.Packet.Publish{}}}
  • {:ex_mqtt, client_pid, {:connected, %ExMqtt.Protocol.Packet.Connack{}}}
  • {:ex_mqtt, client_pid, {:disconnected, reason}}
  • {:ex_mqtt, client_pid, {:auth, %ExMqtt.Protocol.Packet.Auth{}}}

Summary

Callbacks

handle_auth(t, state)

(optional)
@callback handle_auth(ExMqtt.Protocol.Packet.Auth.t(), state :: term()) ::
  {:ok, new_state :: term()}
  | {:reply, ExMqtt.Protocol.Packet.Auth.t(), new_state :: term()}

handle_connect(t, state)

(optional)
@callback handle_connect(ExMqtt.Protocol.Packet.Connack.t(), state :: term()) ::
  {:ok, new_state :: term()}

handle_disconnect(reason, state)

(optional)
@callback handle_disconnect(reason :: term(), state :: term()) ::
  {:ok, new_state :: term()}

handle_message(t, state)

@callback handle_message(ExMqtt.Protocol.Packet.Publish.t(), state :: term()) ::
  {:ok, new_state :: term()}

init(arg)

@callback init(arg :: term()) :: {:ok, state :: term()}