MessageIn Event

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

Syntax

ANSI (Cross Platform)
virtual int FireMessageIn(MQTTMessageInEventParams *e);
typedef struct {
int PacketId;
const char *Topic;
int QOS;
const char *Message; int lenMessage;
int Retained;
int Duplicate; int reserved; } MQTTMessageInEventParams; Unicode (Windows) virtual INT FireMessageIn(MQTTMessageInEventParams *e);
typedef struct {
INT PacketId;
LPCWSTR Topic;
INT QOS;
LPCSTR Message; INT lenMessage;
BOOL Retained;
BOOL Duplicate; INT reserved; } MQTTMessageInEventParams;
- (void)onMessageIn:(int)packetId :(NSString*)topic :(int)QOS :(NSData*)message :(BOOL)retained :(BOOL)duplicate;
#define EID_MQTT_MESSAGEIN 7

virtual INT IPWORKSIOT_CALL FireMessageIn(INT &iPacketId, LPSTR &lpszTopic, INT &iQOS, LPSTR &lpMessage, INT &lenMessage, BOOL &bRetained, BOOL &bDuplicate);

Remarks

The MessageIn event fires once for each incoming message either immediately after it is received (QoS 0), or after it has been fully acknowledged (QoS 1 and 2).

  • PacketId: The message packet Id. This will always be -1 if QOS is 0.
  • Topic: The message's topic string.
  • 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.

Refer to MessageAck for more information about QoS 1 and 2 message processing steps.


// MessageIn event handler.
mqtt1.OnMessageIn += (s, e) => {
  Console.WriteLine("Received message from topic '" + e.Topic + "' with QoS " + e.QOS + ":");
  Console.WriteLine(e.Message);
};

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