publish method
int
publish(
- PublicationTopic topic,
- MqttQos qualityOfService,
- Uint8Buffer data, [
- bool retain = false,
override
Publish a message to the broker on the specified topic. The topic to send the message to The QOS to use when publishing the message. The message to send. The message identifier assigned to the message.
Implementation
@override
int publish(
PublicationTopic topic, MqttQos qualityOfService, typed.Uint8Buffer data,
[bool retain = false]) {
MqttLogger.log(
'PublishingManager::publish - entered with topic ${topic.rawTopic}');
final msgId = messageIdentifierDispenser.getNextMessageIdentifier();
final msg = MqttPublishMessage()
.toTopic(topic.toString())
.withMessageIdentifier(msgId)
.withQos(qualityOfService)
.publishData(data);
// Retain
msg.setRetain(state: retain);
// QOS level 1 or 2 messages need to be saved so we can do the ack processes
if (qualityOfService == MqttQos.atLeastOnce ||
qualityOfService == MqttQos.exactlyOnce) {
publishedMessages[msgId] = msg;
}
connectionHandler!.sendMessage(msg);
return msgId;
}