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(Buffer |
Creates a new Message object |
Properties
ack | Type of feedback requested (in case of cloud-to-device command) |
content |
Content encoding of the message body. can be 'utf-8', 'utf-16' or 'utf-32'. |
content |
Content type property used to routes with the message body. Should be 'application/json'. |
correlation |
Used in message responses and feedback |
data | |
expiry |
Expiry time in UTC interpreted by hub on C2D messages. Ignored in other cases. |
interface |
Is this message a security message |
lock |
Used to Abandon, Reject or Accept the message |
message |
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. |
user |
Used to specify the entity creating the message |
Methods
get |
Gets the data passed to the constructor as a Buffer |
get |
Gets the content (body) of the Message. |
is |
Returns true if the given object is of type BufferConvertible. Objects of type BufferConvertible can be passed into the Message constructor. |
set |
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()
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()