TsgcWSPClient_MQTT › 事件 › OnMQTTPubRec
在 QoS 2 握手的第二阶段(PUBLISH → PUBREC → PUBREL → PUBCOMP)触发。
property OnMQTTPubRec: TsgcWSMQTTPubRecEvent;
// TsgcWSMQTTPubRecEvent = procedure(Connection: TsgcWSConnection; aPacketIdentifier: Word; ReasonCode: Integer; const ReasonName: String; PubRecProperties: TsgcWSMQTTPUBRECProperties) of object
—
QoS 2 通过四步握手保证恰好一次投递:PUBLISH → PUBREC → PUBREL → PUBCOMP。当代理用 PUBREC 数据包确认原始 PUBLISH 时,OnMQTTPubRec 触发,表明代理已接受该消息进入恰好一次流程。组件自动回复 PUBREL 以继续握手;最终的 PUBCOMP 将通过 OnMQTTPubComp 到达。参数:
procedure TForm1.MQTTPubRec(Connection: TsgcWSConnection;
aPacketIdentifier: Word; ReasonCode: Integer;
const ReasonName: String;
PubRecProperties: TsgcWSMQTTPUBRECProperties);
begin
// second leg of QoS 2: broker has the message, PUBREL is sent automatically
Memo1.Lines.Add(Format('PUBREC id=%d (%s)',
[aPacketIdentifier, ReasonName]));
end;