- How to?
- Quality of service (QoS)
MQTT is a "publish-subscribe" messaging protocol based on the TCP/IP protocol. From version 3.1.1, MQTT is an OASIS standard.
Two elements are found in MQTT :
- the client, who publishes messages and who can subscribe to them.
- the broker ("server") that receives the publications from clients, that processes them and that sends them to the clients who subscribed.
Several MQTT brokers are available (ActiveMQ, JoramMQ, OW2 JORAM, Mosquitto, RabbitMQ) as well as iOT servers compatible with MQTT (Amazon iOT, Azure iOT, etc.).
WINDEV, WEBDEV and WINDEV Mobile allow you to manage a MQTT client: you have the ability to publish publications and to subscribe to them.
To implement a management of MQTT client:
- Define a mqttSession variable corresponding to the information required to connect to the MQTT broker.
- Connect to the broker (MQTTConnect).
- You can:
- Publish a message (MQTTPublish). In this case, you must define:
- the topic,
- the quality of service (see below),
- the message (not exceeding 256 MB),
- whether the message must be stored (or not) on the server.
- Subscribe to a message (MQTTSubscribe).
- Unsubscribe (MQTTUnsubscribe, MQTTUnsubscribeAll)
- Disconnect (MQTTDisconnect).
Quality of service (QoS)
When publishing a message, the client defines the requested quality:
- Message of QoS level 0 "At most once": The message will be delivered once at most. The message is not stored. It is sent without guarantee of receipt. The MQTT (broker) does not inform the sender that the message was received. The message can be lost if the client is disconnected or if the server is stopped.
- Message of QoS level 1 "At least once": The message will be delivered at least once. The client will transmit the message several times if necessary until the server (broker) confirms that the message was transmitted on the network.
- Message of QoS level 2 "Exactly once": The message will be necessarily saved by the issuer. It will be transmitted as long as the receiver does not confirm its sending on the network. The issuer is using a sophisticated recognition with the server (broker) to avoid duplicating messages. This mode is slower but it is more secure.
This page is also available for…