MessageAck Event

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

Syntax

class MQTTMessageAckEventParams {
public:
  int PacketId();
  int Direction();
  int Index();
  int ResponseCode();
  int EventRetVal();
  void SetEventRetVal(int iRetVal);
};
// To handle, connect one or more slots to this signal. void MessageAck(MQTTMessageAckEventParams *e);
// Or, subclass MQTT and override this emitter function. virtual int FireMessageAck(MQTTMessageAckEventParams *e) {...}

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 IncomingMessage* properties or OutgoingMessage* properties.
  • 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 IncomingMessage* when the class receives the PUBLISH packet.
  2. The class sends a PUBACK (publish acknowledgment) packet in response.
  3. The MessageAck event is fired.
  4. The message is removed from IncomingMessage*.
  5. The MessageIn event is fired.

Incoming messages with a QoS of 2 follow these steps:

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

Outbound Message Processing

Outgoing messages with a QoS of 1 follow these steps:

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

Outgoing messages with a QoS of 2 follow these steps:

  1. The class sends the PUBLISH packet, then adds the message to OutgoingMessage*.
  2. The class waits to receive a PUBREC (publish received) packet.
  3. The class sends a PUBREL (publish release) packet in response.
  4. The class waits to receive a PUBCOMP (publish complete) packet.
  5. The MessageAck event is fired.
  6. The message is removed from OutgoingMessage*.
  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 class 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 Qt Edition - Version 20.0 [Build 8155]