TsgcWSPClient_MQTTEvents › OnMQTTPublish

OnMQTTPublish 事件

当代理投递传入的 PUBLISH 消息时触发;公开 Topic、Text 和 MQTT 5 PublishProperties。

语法

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

默认值

备注

主要投递事件:每当代理将 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;

返回事件