TsgcWSPClient_MQTT › Events › OnMQTTPublish
Se déclenche lorsque le courtier livre un message PUBLISH entrant ; expose Topic, Text et MQTT 5 PublishProperties.
property OnMQTTPublish: TsgcWSMQTTPublishEvent;
// TsgcWSMQTTPublishEvent = procedure(Connection: TsgcWSConnection; aTopic, aText: String; PublishProperties: TsgcWSMQTTPUBLISHProperties) of object
—
Événement de livraison principal : déclenché chaque fois que le broker transfère un PUBLISH à ce client pour un sujet correspondant à l'un de ses abonnements. Quel que soit le QoS de publication (0, 1 ou 2), l'événement se déclenche après la complétion de la séquence d'accusé de réception au niveau transport : QoS 0 est fire-and-forget, QoS 1 après PUBACK, QoS 2 après l'échange PUBREC/PUBREL/PUBCOMP. Paramètres :
procedure TForm1.MQTTPublish(Connection: TsgcWSConnection;
aTopic, aText: String;
PublishProperties: TsgcWSMQTTPUBLISHProperties);
begin
Memo1.Lines.Add(Format('[%s] %s', [aTopic, aText]));
// MQTT 5: honour a ResponseTopic if the sender set one
if PublishProperties.ResponseTopic <> '' then
MQTT.Publish(PublishProperties.ResponseTopic, 'ack', mtqsAtMostOnce);
end;