Class: Message

Message

A wrapper of the PUBLISH Control Packet, used to transport an Application Message from an MqttClient to an MQTT broker and vice versa, through an end-to-end connection.

new Message(payloadnon-null)

Constructs a PUBLISH Control Packet wrapper starting from a payload, which can be specified in different formats.
Parameters:
Name Type Description
payload string | ArrayBuffer | Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array The payload containing the Application Message
Throws:
If the provided payload is not of the expected type.
Type
Error

Members

destinationName :string

The name of the topic to which the Application Message is published. This property is mandatory when sending an Application Message through the MqttClient#send method.

When setting this property, an Error is thrown if the provided value is not of string type.

Type:
  • string

(readonly) duplicate :boolean

The duplicate flag. If set to true, indicates that the PUBLISH Control Packet containing the Application Message could be a redelivery of an earlier attempt.

Note that this is a read only property as it can only be set on the instances received from the MQTT broker.

Type:
  • boolean
Default Value:
  • false

(readonly) payloadBytes :ArrayBuffer

The payload as an ArrayBuffer.
Type:
  • ArrayBuffer

(readonly) payloadString :string

The payload as a string.
Type:
  • string

qos :number

The Quality of Service level for delivery of the Application Message as specified below:
  • 0 - At most once delivery
  • 1 - At least once delivery
  • 2 - Exactly once delivery

When setting this property, an Error is thrown if the provided value is different from any of the ones specified above.

Type:
  • number
Default Value:
  • 0

retained :boolean

The retained flag. If set to true, specifies that the MQTT broker has to store the Application Message and its QoS, so that the PUBLISH Control Packet can be delivered to clients immediately after they subscribe to a matching topic name.

A Message instance received from the MQTT broker has the retain flag set to true, if the message is sent as a consequence of a subscription made after the message has been published with the retain flag set to true.

When setting this property, an Error is thrown if the provided value is not of boolean type.

Type:
  • boolean
Default Value:
  • false