RetryMQTT.publish()
Overview
Publishes a message to the MQTT broker, or if not connected, queues the message to be sent when reconnected. This is a simplified version of MQTTClient.publish() without callbacks.
All messages are sent with the QOS of 1 (At least once).
Sending too many messages while disconnected may cause the oldest messages to be discarded. See the maxQueueLength option for the RetryMQTT constructor.
Added in version 2.1.20
Format
var retryMqtt = new RetryMQTT(options);
//...
retryMqtt.publish(topic, payload, retain);
Value | Description | Type | Required |
---|---|---|---|
topic | The topic for the message. | String | Required |
payload | A string or an ArrayBuffer containing the payload for the message. | ArrayBuffer or String | Required |
retain | A flag indicating if this message is a retained message. | Boolean | Optional |
Example
/* Connect, send a message with QoS 1 (at least once)
*/
retryMqtt = new RetryMQTT({
broker: "mqtt://mymqtt.example.com"
});
retryMqtt.publish("this/is/a/test", "tada: " + Date.now());