서버가 보낸 메시지는 OnMQTTPublish 이벤트에서 수신됩니다. 이 이벤트에는 다음 매개변수가 있습니다:
Topic: 이 메시지와 연결된 topic의 이름입니다.
Text: 메시지의 텍스트입니다.
PublishProperties: MQTT 5.0인 경우, 게시된 메시지의 속성입니다.
procedure OnMQTTPublish(Connection: TsgcWSConnection; aTopic, aText: string;
PublishProperties: TsgcWSMQTTPublishProperties);
begin
WriteLn('Topic: ' + aTopic + '. Message: ' + aText);
end;
OnMQTTPublishEx 이벤트는 TsgcWSMQTTPublishData 객체를 통해 게시된 메시지 페이로드를 여러 형식으로 제공합니다. 이 이벤트에는 다음 매개변수가 있습니다:
Topic: 이 메시지와 연결된 topic의 이름입니다.
Data: 게시된 메시지의 페이로드를 포함합니다. 다음 속성을 가집니다:
Value: 문자열 형태의 페이로드.
Bytes: TBytes 형식의 원시 페이로드입니다.
Stream: TMemoryStream 형식의 원시 페이로드입니다.
PublishProperties: MQTT 5.0인 경우, 게시된 메시지의 속성입니다.
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;