TsgcWSPClient_MQTT | MQTT Receive Messages

Messages sent by the server are received in the OnMQTTPublish event. This event has the following parameters:

 

Topic: is the name of the topic associated to this message.

Text: is the text of the message.

PublishProperties: if MQTT 5.0, these are the properties of the published message.

 

Read published Messages


procedure OnMQTTPublish(Connection: TsgcWSConnection; aTopic, aText: string;
  PublishProperties: TsgcWSMQTTPublishProperties);
begin
  WriteLn('Topic: ' + aTopic + '. Message: ' + aText);
end;

TsgcWSPClient_MQTT | MQTT Receive Messages (Extended)

The OnMQTTPublishEx event provides the published message payload in multiple formats through a TsgcWSMQTTPublishData object. This event has the following parameters:

 

Topic: is the name of the topic associated to this message.

Data: contains the payload of the published message. It has the following properties:

PublishProperties: if MQTT 5.0, these are the properties of the published message.

 

Read published Messages (Extended)


procedure OnMQTTPublishEx(Connection: TsgcWSConnection; aTopic: string;
  aData: TsgcWSMQTTPublishData; PublishProperties: TsgcWSMQTTPublishProperties);
begin
  // read as string
  WriteLn('Topic: ' + aTopic + '. Message: ' + aData.Value);
  // read as bytes
  WriteLn('Bytes Length: ' + IntToStr(Length(aData.Bytes)));
  // read as stream
  WriteLn('Stream Size: ' + IntToStr(aData.Stream.Size));
end;