MqttX.Server.SessionBackend.Replicated (MqttX v0.13.0)

Copy Markdown View Source

A MqttX.Server.SessionBackend that keeps every saved session on every node running the listener, in memory: when a node goes down, a client of its resumes its session on any other node.

MqttX.Server.start_link(MyBroker, [],
  name: MyApp.Broker,
  port: 1883,
  session_backend: MqttX.Server.SessionBackend.Replicated
)

Each save goes to every other node of the listener's group (the listeners with the same :name on connected nodes, see MqttX.Server.Cluster), and a node that joins is sent what the others hold. A record carries the node that saved it and a version; a node keeps the newest version of each session, so a save that arrives late cannot replace a newer one. Versions combine the wall clock with the version they replace, which orders the saves of a session moving between nodes as long as the nodes' clocks agree to within the time the move takes.

Costs: every node holds every persistent session, and each change to one is sent to every node (once per :session_flush_interval, like any backend). A node that dies loses at most that much of its sessions' changes; a session saved while connected starts its expiry clock when its node leaves.

The records live as long as one node runs the listener: a restart of the whole cluster loses them. For that, implement the behaviour over a database.

Summary

Functions

Returns a specification to start this module under a supervisor.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.