MessageAck Event

Fired when an incoming or outgoing message has completed all acknowledgment steps.

Syntax

public event OnMessageAckHandler OnMessageAck;

public delegate void OnMessageAckHandler(object sender, MqttMessageAckEventArgs e);

public class MqttMessageAckEventArgs : EventArgs {
  public int PacketId { get; }
  public int Direction { get; }
  public int Index { get; }
  public int ResponseCode { get; }
}
Public Event OnMessageAck As OnMessageAckHandler

Public Delegate Sub OnMessageAckHandler(sender As Object, e As MqttMessageAckEventArgs)

Public Class MqttMessageAckEventArgs Inherits EventArgs
  Public ReadOnly Property PacketId As Integer
  Public ReadOnly Property Direction As Integer
  Public ReadOnly Property Index As Integer
  Public ReadOnly Property ResponseCode As Integer
End Class

Remarks

The MessageAck event fires once an incoming or outgoing message with a QoS of 1 or 2 has successfully completed all acknowledgment steps as required by its QoS level. (Note that this event does not fire for messages with a QoS of 0 since they do not require acknowledgment.)

  • PacketId: The Id of the original PUBLISH packet for the message.
  • Direction: Shows whether the client (0) or the server (1) is sending the data.
  • Index: The index at which the message resides in either the IncomingMessages collection or OutgoingMessages collection.
  • ResponseCode: In MQTT 5, all response packets contain Reason Codes. This argument contains any code encountered in message acknowledgment packets (PUBACK, PUBREC, PUBREL, PUBCOMP).

Possible MQTT-specific values for ResponseCode are:

Value Applicable packets Description
0 PUBACK, PUBREC, PUBREL, PUBCOMP Success
16 PUBACK, PUBREC No matching subscribers
128 PUBACK, PUBREC Unspecified error
131 PUBACK, PUBREC Implementation specific error
135 PUBACK, PUBREC Not authorized
144 PUBACK, PUBREC Topic Name invalid
145 PUBACK, PUBREC Packet Identifier in use
146 PUBREL, PUBCOMP Packet Identifier not found

Inbound Message Processing

Incoming messages with a QoS of 1 follow these steps:

  1. The message is added to IncomingMessages when the component receives the PUBLISH packet.
  2. The component sends a PUBACK (publish acknowledgment) packet in response.
  3. The MessageAck event is fired.
  4. The message is removed from IncomingMessages.
  5. The MessageIn event is fired.

Incoming messages with a QoS of 2 follow these steps:

  1. The message is added to IncomingMessages when the component receives the PUBLISH packet.
  2. The component sends a PUBREC (publish received) packet in response.
  3. The component waits to receive a PUBREL (publish release) packet.
  4. The component sends a PUBCOMP (publish complete) packet in response.
  5. The MessageAck event is fired.
  6. The message is removed from IncomingMessages.
  7. The MessageIn event is fired.

Outbound Message Processing

Outgoing messages with a QoS of 1 follow these steps:

  1. The component sends the PUBLISH packet, then adds the message to OutgoingMessages.
  2. The component waits to receive a PUBACK (publish acknowledgment) packet.
  3. The MessageAck event is fired.
  4. The message is removed from OutgoingMessages.
  5. The MessageOut event is fired.

Outgoing messages with a QoS of 2 follow these steps:

  1. The component sends the PUBLISH packet, then adds the message to OutgoingMessages.
  2. The component waits to receive a PUBREC (publish received) packet.
  3. The component sends a PUBREL (publish release) packet in response.
  4. The component waits to receive a PUBCOMP (publish complete) packet.
  5. The MessageAck event is fired.
  6. The message is removed from OutgoingMessages.
  7. The MessageOut event is fired.

In MQTT 3.1.1, the RepublishInterval configuration setting, if set to a non-zero value (default), controls how long the component will wait to receive a PUBACK (for QoS 1) or PUBREC (for QoS 2) before automatically republishing an outgoing message. In MQTT 5, messages are only republished if the client is disconnected before receiving a PUBACK or PUBREC.

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks MQ 2020 .NET Edition - Version 20.0 [Build 8162]