TsgcWSPClient_MQTTEvents › OnMQTTPubRec

OnMQTTPubRec Event

Fires on the second leg of the QoS 2 handshake (PUBLISH → PUBREC → PUBREL → PUBCOMP).

Syntax

property OnMQTTPubRec: TsgcWSMQTTPubRecEvent;
// TsgcWSMQTTPubRecEvent = procedure(Connection: TsgcWSConnection; aPacketIdentifier: Word; ReasonCode: Integer; const ReasonName: String; PubRecProperties: TsgcWSMQTTPUBRECProperties) of object

Default Value

Remarks

QoS 2 guarantees exactly-once delivery via a four-packet handshake: PUBLISH → PUBREC → PUBREL → PUBCOMP. OnMQTTPubRec fires when the broker acknowledges the original PUBLISH with a PUBREC packet, signalling that the broker has accepted the message for the exactly-once flow. The component automatically replies with PUBREL to continue the handshake; the final PUBCOMP will arrive on OnMQTTPubComp. Parameters:

Example

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;

Back to Events