TsgcWSPClient_MQTTイベント › OnMQTTPublish

OnMQTTPublish イベント

ブローカーが受信 PUBLISH メッセージを配信したときに発火します。Topic、Text、MQTT 5 の PublishProperties を公開します。

構文

property OnMQTTPublish: TsgcWSMQTTPublishEvent;
// TsgcWSMQTTPublishEvent = procedure(Connection: TsgcWSConnection; aTopic, aText: String; PublishProperties: TsgcWSMQTTPUBLISHProperties) of object

デフォルト値

解説

メインの配信イベント: ブローカーがサブスクリプションの1つに一致するトピックに対してPUBLISHをこのクライアントに転送するたびに発生します。パブリッシュQoS(0、1、2)に関わらず、イベントはトランスポートレベルの確認応答シーケンスが完了した後に発火します。QoS 0は発射忘れ、QoS 1はPUBACK後、QoS 2はPUBREC/PUBREL/PUBCOMPの交換後です。パラメータ:

使用例

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;

イベントに戻る