Message class

The Message object is used for telemetry (device-to-cloud) and commands (cloud-to-device) asynchronous messaging between the device and the IoT Hub service. It is transport-agnostic, meaning it works the same way over AMQP, MQTT and HTTP.

Constructors

Message(BufferConvertible)

Creates a new Message object

Properties

ack

Type of feedback requested (in case of cloud-to-device command)

contentEncoding

Content encoding of the message body. can be 'utf-8', 'utf-16' or 'utf-32'.

contentType

Content type property used to routes with the message body. Should be 'application/json'.

correlationId

Used in message responses and feedback

data
expiryTimeUtc

Expiry time in UTC interpreted by hub on C2D messages. Ignored in other cases.

interfaceId

Is this message a security message

lockToken

Used to Abandon, Reject or Accept the message

messageId

Used to correlate two-way communication. Format: A case-sensitive string (up to 128 char long) of ASCII 7-bit alphanumeric chars and the following special symbols:
- : . + % _ # * ? ! ( ) , = @ ; $ '.

properties

A map containing string keys and values for storing custom message properties.

to

Destination of the message.

userId

Used to specify the entity creating the message

Methods

getBytes()

Gets the data passed to the constructor as a Buffer

getData()

Gets the content (body) of the Message.

isBufferConvertible(any)

Returns true if the given object is of type BufferConvertible. Objects of type BufferConvertible can be passed into the Message constructor.

setAsSecurityMessage()

Sets this message as a security message

Constructor Details

Message(BufferConvertible)

Creates a new Message object

new Message(data: BufferConvertible)

Parameters

data
BufferConvertible

a Node Buffer object or anything that can be passed to the Buffer constructor to construct a Buffer from.

Property Details

ack

Type of feedback requested (in case of cloud-to-device command)

ack: string

Property Value

string

contentEncoding

Content encoding of the message body. can be 'utf-8', 'utf-16' or 'utf-32'.

contentEncoding: undefined | "utf-8" | "utf-16" | "utf-32"

Property Value

undefined | "utf-8" | "utf-16" | "utf-32"

contentType

Content type property used to routes with the message body. Should be 'application/json'.

contentType: undefined | "application/json"

Property Value

undefined | "application/json"

correlationId

Used in message responses and feedback

correlationId: string

Property Value

string

data

data: any

Property Value

any

expiryTimeUtc

Expiry time in UTC interpreted by hub on C2D messages. Ignored in other cases.

expiryTimeUtc: any

Property Value

any

interfaceId

Is this message a security message

interfaceId: string

Property Value

string

lockToken

Used to Abandon, Reject or Accept the message

lockToken: string

Property Value

string

messageId

Used to correlate two-way communication. Format: A case-sensitive string (up to 128 char long) of ASCII 7-bit alphanumeric chars and the following special symbols:
- : . + % _ # * ? ! ( ) , = @ ; $ '.

messageId: string

Property Value

string

properties

A map containing string keys and values for storing custom message properties.

properties: Properties

Property Value

Properties

to

Destination of the message.

to: string

Property Value

string

userId

Used to specify the entity creating the message

userId: string

Property Value

string

Method Details

getBytes()

Gets the data passed to the constructor as a Buffer

function getBytes(): Buffer

Returns

Buffer

getData()

Gets the content (body) of the Message.

function getData(): BufferConvertible

Returns

The content of the Message.

isBufferConvertible(any)

Returns true if the given object is of type BufferConvertible. Objects of type BufferConvertible can be passed into the Message constructor.

static function isBufferConvertible(obj: any): boolean

Parameters

obj

any

object instance to check

Returns

boolean

True if the object is of type BufferConvertible

setAsSecurityMessage()

Sets this message as a security message

function setAsSecurityMessage()