MessageIn Event

Fired when an incoming message has been received and/or fully acknowledged.

Syntax

ANSI (Cross Platform)
virtual int FireMessageIn(MQTTSNMessageInEventParams *e);
typedef struct {
int MsgId;
const char *TopicId;
int TopicIdType;
int QOS;
const char *Message; int lenMessage;
int Retained;
int Duplicate;
int ReturnCode; int reserved; } MQTTSNMessageInEventParams; Unicode (Windows) virtual INT FireMessageIn(MQTTSNMessageInEventParams *e);
typedef struct {
INT MsgId;
LPCWSTR TopicId;
INT TopicIdType;
INT QOS;
LPCSTR Message; INT lenMessage;
BOOL Retained;
BOOL Duplicate;
INT ReturnCode; INT reserved; } MQTTSNMessageInEventParams;
- (void)onMessageIn:(int)msgId :(NSString*)topicId :(int)topicIdType :(int)QOS :(NSData*)message :(BOOL)retained :(BOOL)duplicate :(int*)returnCode;
#define EID_MQTTSN_MESSAGEIN 7

virtual INT IPWORKSIOT_CALL FireMessageIn(INT &iMsgId, LPSTR &lpszTopicId, INT &iTopicIdType, INT &iQOS, LPSTR &lpMessage, INT &lenMessage, BOOL &bRetained, BOOL &bDuplicate, INT &iReturnCode);

Remarks

Fired on reception of a PUBLISH packet for QoS 0 and 1 messages, and reception of a PUBREL packet for QoS 2 messages.

  • MsgId: a unique (among currently unacknowledged incoming messages) identifier attached to messages of QoS 1 and 2. Otherwise value will be 0.
  • TopicId: topic id of type TopicIdType.
  • TopicIdType: 0 = registered topic id, 1 = pre-defined topic id, 2 = short topic name.
  • QOS: The message's QoS level.
  • Message: The message data.
  • Retained: Whether or not this message was received as a result of subscribing to a topic.
  • Duplicate: Whether or not the server has indicated that this message is a duplicate of another message sent previously.
  • ReturnCode: QoS 1 messages can be accepted or rejected by setting the ReturnCode to a value listed below.
    • 0: accepted
    • 1: rejected - congestion
    • 2: rejected - invalid topic id
    • 3: rejected - not supported

Inbound Message Processing

Incoming messages with a QoS of 1 follow these steps:

  1. The TopicInfo event is fired (if the gateway sends a REGISTER packet because it needs to inform the client name and assigned topic id it will use in a PUBLISH message).
  2. The class sends a REGACK (register acknowledgment) packet in response (if a REGISTER packet was received).
  3. The MessageIn event is fired.
  4. The class sends a PUBACK (publish acknowledgment) packet in response (with the return code from the MessageIn event if one is set).

Incoming messages with a QoS of 2 follow these steps:

  1. The TopicInfo event is fired (if the gateway sends a REGISTER packet because it needs to inform the client name and assigned topic id it will use in a PUBLISH message).
  2. The class sends a REGACK (register acknowledgment) packet in response (if a REGISTER packet was received).
  3. The class sends a PUBREC (publish received) packet in response.
  4. The class waits to receive a PUBREL (publish release) packet.
  5. The class sends a PUBCOMP (publish complete) packet in response.
  6. The MessageIn event is fired.

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks IoT 2020 C++ Edition - Version 20.0 [Build 8265]