你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Message class

Message 对象用于设备与 IoT 中心服务之间的遥测(设备到云)和命令(云到设备)异步消息传送。 它与传输无关,这意味着它的工作方式与 AMQP、MQTT 和 HTTP 的工作方式相同。

构造函数

Message(BufferConvertible)

创建新的 Message 对象

属性

ack

请求的反馈类型(在云到设备命令的情况下)

contentEncoding

消息正文的内容编码。 可以是“utf-8”、“utf-16”或“utf-32”。

contentType

用于路由消息正文的内容类型属性。 应为“application/json”。

correlationId

在消息响应和反馈中使用

data
expiryTimeUtc

C2D 消息上中心解释的 UTC 到期时间。 在其他情况下忽略。

interfaceId

此消息是否为安全消息

lockToken

用于放弃、拒绝或接受邮件

messageId

用于关联双向通信。 格式:ASCII 7 位字母数字字符和以下特殊符号的区分大小写的字符串(最多为 128 个字符):
- : . + % _ # * ? ! ( ) , = @ ; $ '

properties

包含用于存储自定义消息属性的字符串键和值的映射。

to

消息的目标。

userId

用于指定创建消息的实体

方法

getBytes()

获取作为 缓冲区 传递给构造函数的数据

getData()

获取 Message的内容(正文)。

isBufferConvertible(any)

如果给定对象的类型 BufferConvertible,则返回 true。 BufferConvertible 类型的对象可以传递到 消息 构造函数中。

setAsSecurityMessage()

将此消息设置为安全消息

构造函数详细信息

Message(BufferConvertible)

创建新的 Message 对象

new Message(data: BufferConvertible)

参数

data
BufferConvertible

Node Buffer 对象或可传递给 Buffer 构造函数的任何内容,以构造 Buffer

属性详细信息

ack

请求的反馈类型(在云到设备命令的情况下)

ack: string

属性值

string

contentEncoding

消息正文的内容编码。 可以是“utf-8”、“utf-16”或“utf-32”。

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

属性值

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

contentType

用于路由消息正文的内容类型属性。 应为“application/json”。

contentType: undefined | "application/json"

属性值

undefined | "application/json"

correlationId

在消息响应和反馈中使用

correlationId: string

属性值

string

data

data: any

属性值

any

expiryTimeUtc

C2D 消息上中心解释的 UTC 到期时间。 在其他情况下忽略。

expiryTimeUtc: any

属性值

any

interfaceId

此消息是否为安全消息

interfaceId: string

属性值

string

lockToken

用于放弃、拒绝或接受邮件

lockToken: string

属性值

string

messageId

用于关联双向通信。 格式:ASCII 7 位字母数字字符和以下特殊符号的区分大小写的字符串(最多为 128 个字符):
- : . + % _ # * ? ! ( ) , = @ ; $ '

messageId: string

属性值

string

properties

包含用于存储自定义消息属性的字符串键和值的映射。

properties: Properties

属性值

Properties

to

消息的目标。

to: string

属性值

string

userId

用于指定创建消息的实体

userId: string

属性值

string

方法详细信息

getBytes()

获取作为 缓冲区 传递给构造函数的数据

function getBytes(): Buffer

返回

Buffer

getData()

获取 Message的内容(正文)。

function getData(): BufferConvertible

返回

Message的内容。

isBufferConvertible(any)

如果给定对象的类型 BufferConvertible,则返回 true。 BufferConvertible 类型的对象可以传递到 消息 构造函数中。

static function isBufferConvertible(obj: any): boolean

参数

obj

any

要检查的对象实例

返回

boolean

如此 如果对象的类型为 BufferConvertible

setAsSecurityMessage()

将此消息设置为安全消息

function setAsSecurityMessage()