MessageIn Event

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

Syntax

public event OnMessageInHandler OnMessageIn;

public delegate void OnMessageInHandler(object sender, MqttsnMessageInEventArgs e);

public class MqttsnMessageInEventArgs : EventArgs {
  public int MsgId { get; }
  public string TopicId { get; }
  public int TopicIdType { get; }
  public int QOS { get; }
  public string Message { get; }
public byte[] MessageB { get; } public bool Retained { get; } public bool Duplicate { get; } public int ReturnCode { get; set; } }
Public Event OnMessageIn As OnMessageInHandler

Public Delegate Sub OnMessageInHandler(sender As Object, e As MqttsnMessageInEventArgs)

Public Class MqttsnMessageInEventArgs Inherits EventArgs
  Public ReadOnly Property MsgId As Integer
  Public ReadOnly Property TopicId As String
  Public ReadOnly Property TopicIdType As Integer
  Public ReadOnly Property QOS As Integer
  Public ReadOnly Property Message As String
Public ReadOnly Property MessageB As Byte() Public ReadOnly Property Retained As Boolean Public ReadOnly Property Duplicate As Boolean Public Property ReturnCode As Integer End Class

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 component sends a REGACK (register acknowledgment) packet in response (if a REGISTER packet was received).
  3. The MessageIn event is fired.
  4. The component 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 component sends a REGACK (register acknowledgment) packet in response (if a REGISTER packet was received).
  3. The component sends a PUBREC (publish received) packet in response.
  4. The component waits to receive a PUBREL (publish release) packet.
  5. The component 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 .NET Edition - Version 20.0 [Build 8265]