publishMessage method
int
publishMessage(
- String topic,
- MqttQos qualityOfService,
- Uint8Buffer data, {
- bool retain = false,
- List<
MqttUserProperty> ? userProperties,
Publishes a message to the message broker. Returns the message identifer assigned to the message. Raises InvalidTopicException if the topic supplied violates the MQTT topic format rules.
Implementation
int publishMessage(
String topic, MqttQos qualityOfService, typed.Uint8Buffer data,
{bool retain = false, List<MqttUserProperty>? userProperties}) {
if (connectionHandler?.connectionStatus?.state !=
MqttConnectionState.connected) {
throw MqttConnectionException(connectionHandler?.connectionStatus?.state);
}
try {
final pubTopic = MqttPublicationTopic(topic);
return publishingManager!.publish(pubTopic, qualityOfService, data,
retain: retain, userProperties: userProperties);
} on Exception catch (e) {
throw MqttInvalidTopicException(e.toString(), topic);
}
}