你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
MQTT 路由消息的事件架构
MQTT 消息根据以下逻辑作为 CloudEvents 路由到事件网格主题:
对于有效负载格式指示符为 0 的 MQTT v3 消息或 MQTT v5 消息,有效负载将在 data_base64 对象中转发,并根据以下架构示例编码为 base 64 字符串。
{
"specversion": "1.0",
"id": "9aeb0fdf-c01e-0131-0922-9eb54906e20", // unique id stamped by the service.
"time": "2019-11-18T15:13:39.4589254Z", // timestamp when the message was received by the service.
"type": "MQTT.EventPublished", // set type for all MQTT messages enveloped by the service.
"source": "testnamespace", // namespace name
"subject": "campus/buildings/building17", // topic of the MQTT publish request.
"data_base64":
{
IlRlbXAiOiAiNzAiLAoiaHVtaWRpdHkiOiAiNDAiCg==
}
}
对于内容类型为“application/json; charset=utf-8”或有效负载格式指示符为 1 的 MQTT v5 消息,有效负载将在数据对象中转发,消息将序列化为 JSON(如果有效负载不是 JSON,则序列化为 JSON 字符串)。 通过设置内容类型和/或有效负载格式指示符,可以在数据字段中转发有效负载时,按原样根据有效负载属性进行筛选。 详细了解如何根据消息的有效负载进行筛选。
{
"specversion": "1.0",
"id": "9aeb0fdf-c01e-0131-0922-9eb54906e20", // unique id stamped by the service.
"time": "2019-11-18T15:13:39.4589254Z", // timestamp when the message was received by the service.
"type": "MQTT.EventPublished", // set type for all MQTT messages enveloped by the service.
"source": "testnamespace", // namespace name
"subject": "campus/buildings/building17", // topic of the MQTT publish request.
"data":
{
"Temp": 70,
"humidity": 40
}
}
对于已根据 CloudEvents 的 MQTT 协议绑定封装在 CloudEvent 中的 MQTT v5 消息,无论使用二进制内容模式还是 JSON 编码 (utf-8) 的结构化内容模式,在扩充后,都会根据以下架构示例使用原始默认 CloudEvents 属性转发事件。
{
"specversion": "1.0",
"id": "9aeb0fdf-c01e-0131-0922-9eb54906e20", // original id stamped by the client.
"time": "2019-11-18T15:13:39.4589254Z", // timestamp when the message was received by the client
"type": "Custom.Type", // original type value stamped by the client.
"source": "Custom.Source", // original source value stamped by the client.
"subject": " Custom.Subject", // original subjectvalue stamped by the client.
"data":
{
"Temp": "70",
"humidity": "40"
}
}
后续步骤:
使用以下文章详细了解路由: