TsgcWSPClient_MQTT › Events › OnMQTTPublishEx
Fires on incoming PUBLISH; delivers the payload as a TsgcWSMQTTPublishData (Value, Bytes, Stream) plus the raw TsgcWSMQTTMessage.
property OnMQTTPublishEx: TsgcWSMQTTPublishExEvent;
// TsgcWSMQTTPublishExEvent = procedure(Connection: TsgcWSConnection; aTopic: String; aData: TsgcWSMQTTPublishData; PublishProperties: TsgcWSMQTTPUBLISHProperties; aMessage: TsgcWSMQTTMessage) of object
—
Extended variant of OnMQTTPublish for binary payloads and low-level inspection. Fires for every incoming PUBLISH after the transport-level QoS handshake has finished (QoS 0 immediately; QoS 1 after PUBACK; QoS 2 after PUBREC → PUBREL → PUBCOMP). Parameters:
Value (String), Bytes (TBytes) and Stream (TMemoryStream). Pick whichever matches your content (text, binary blob, stream consumer).Handle either OnMQTTPublish or OnMQTTPublishEx (the component delivers incoming messages to whichever is assigned); OnMQTTPublishEx is preferred when the payload is not guaranteed to be valid UTF-8.
procedure TForm1.MQTTPublishEx(Connection: TsgcWSConnection;
aTopic: String; aData: TsgcWSMQTTPublishData;
PublishProperties: TsgcWSMQTTPUBLISHProperties;
aMessage: TsgcWSMQTTMessage);
var
vBytes: TBytes;
begin
Memo1.Lines.Add(Format('[%s] QoS=%d %d bytes',
[aTopic, Ord(aMessage.QoS), Length(aData.Bytes)]));
// read the payload as raw bytes (safe for binary content)
vBytes := aData.Bytes;
// or pull it through the stream API
aData.Stream.Position := 0;
SaveStreamToFile(aData.Stream, 'payload.bin');
end;