MQTT
MQTT (Message Queuing Telemetry Transport) is a real-time messaging protocol for exchanging data by topic with a publish / subscribe approach. A topic is a point (or a set of points) representing a piece of data (or a set of data).
The MQTT protocol is made up of two main types of entities:
- The MQTT broker: collects and makes available the requested data. It plays the role of server.
- The MQTT client: it can publish data to a broker and subscribe topics to receive data from a broker.
OIBus is a MQTT client and uses the MQTT.js library.
Connection settings
Connection
To connect to a broker, the MQTT connector requires some information:
- URL: of the form
mqtt://address:1883
. The default MQTT port is 1883 but may differ depending on the broker’s configuration. - Quality of service (QoS): agreement between the sender of a message and the receiver of a message that defines the
guarantee of delivery for a specific message. Three modes are available:
- QoS 0: at most once. This means that the message is sent once but MQTT does not guarantee that the message will be received correctly. Good reception will depend on the quality of the underlying network of MQTT.
- QoS 1: at least once. This means that the message is sent multiple times as duplicates until the client validates the correct receipt of at least one of the duplicates. In some cases, the client may receive the same message more than once.
- QoS 2: exactly once. This means that the message is sent only once, and a new attempt to send the message takes place after a certain time until the client confirms the good reception. There is no risk of multiple receptions in this case.
- Persistence: Both QoS1 and QoS2 allow persistent connections. A persistent connection allows the broker to keep a certain number of messages in memory (set on the broker) until the client reconnects in case of connection loss. Persistence is ignored for QoS 0.