MQTT client allows the use of some type of QoS levels, any of those levels works in a different level to be sure that messages have been processed as expected.
There are the following QoS levels:
mtqsAtMostOnce: (by default) the message is delivered according to the best efforts of the underlying TCP/IP network. A response is not expected and no retry semantics are defined in the protocol. The message arrives at the server either once or not at all.
mtqsAtLeastOnce: the receipt of a message by the server is acknowledged by an ACKNOWLEDGMENT message. If there is an identified failure of either the communications link or the sending device or the acknowledgement message is not received after a specified period of time, the sender resends the message. The message arrives at the server at least once. A message with QoS level 1 has an ID param in the message.
mtqsExactlyOnce: where message are assured to arrive exactly once. This level could be used, for example, with billing systems where duplicate or lost messages could lead to incorrect charges being applied. If there is an identified failure of either the communications link or the sending device, or the acknowledgement message is not received after a specified period of time, the sender resends the message.
You can handle the events OnPubAck or OnPubComp to know if message has been processed by server or you can use the method PublishAndWait to know if the message has been processed by the server.
The use of PublishAndWait is the same that normal Publish method, now you have a new parameter called Timeout, where method will return with value false if after certain period of time, there is no response from server. By default this value is 10 seconds.
if mqtt.PublishAndWait('topic', 'text') then
ShowMessage('Message processed')
else
ShowMessage('Message error');