比较 IoT 中心的消息路由和事件网格Compare message routing and Event Grid for IoT Hub

Azure IoT 中心可以从已连接的设备流式传输数据并将该数据集成到商业应用程序中。Azure IoT Hub provides the capability to stream data from your connected devices and integrate that data into your business applications. IoT 中心提供了两种将 IoT 事件集成到其他 Azure 服务或商业应用程序的方法。IoT Hub offers two methods for integrating IoT events into other Azure services or business applications. 本文讨论提供此功能的两个功能,以便你可选择最适合你的方案的选项。This article discusses the two features that provide this capability, so that you can choose which option is best for your scenario.

备注

本文中提到的某些功能(例如云到设备消息传递、设备孪生、设备管理)仅在 IoT 中心的标准层中提供。Some of the features mentioned in this article, like cloud-to-device messaging, device twins, and device management, are only available in the standard tier of IoT hub. 有关基本和标准 IoT 中心层的详细信息,请参阅如何选择合适的 IoT 中心层For more information about the basic and standard IoT Hub tiers, see How to choose the right IoT Hub tier.

IoT 中心消息路由 :借助此 IoT 中心功能,用户可将设备到云消息路由到服务终结点,如 Azure 存储容器、事件中心、服务总线队列和服务总线主题。IoT Hub message routing: This IoT Hub feature enables users to route device-to-cloud messages to service endpoints like Azure Storage containers, Event Hubs, Service Bus queues, and Service Bus topics. 路由还提供了一种查询功能,让你先筛选数据,再将其路由到终结点。Routing also provides a querying capability to filter the data before routing it to the endpoints. 除了设备遥测数据之外,还可以发送可用于触发操作的非遥测事件In addition to device telemetry data, you can also send non-telemetry events that can be used to trigger actions.

IoT 中心与事件网格的集成:Azure 事件网格是一种完全托管的事件路由服务,使用发布-订阅模型。IoT Hub integration with Event Grid: Azure Event Grid is a fully managed event routing service that uses a publish-subscribe model. IoT 中心和事件网格共同协作,准实时地将 IoT 中心事件集成到 Azure 和非 Azure 服务中IoT Hub and Event Grid work together to integrate IoT Hub events into Azure and non-Azure services, in near-real time. IoT 中心同时发布设备事件和遥测事件。IoT Hub publishes both device events and telemetry events.

差异Differences

尽管消息路由和事件网格都启用了警报配置,但两者之间存在一些重要差异。While both message routing and Event Grid enable alert configuration, there are some key differences between the two. 有关详细信息,请参照下表:Refer to the following table for details:

FeatureFeature IoT 中心消息路由IoT Hub message routing IoT 中心与事件网格的集成IoT Hub integration with Event Grid
设备消息和事件Device messages and events 是,消息路由可以用于遥测数据、报告设备孪生更改和设备生命周期事件(例如,Yes, message routing can be used for telemetry data, report device twin changes, device lifecycle events (ex. 何时创建、删除、连接设备以及何时让设备与 IoT 中心断开连接)以及数字孪生体更改事件。when devices are created, deleted, connected and disconnected from IoT Hub), and digital twin change events. 是,事件网格可用于遥测数据和设备生命周期事件。Yes, Event Grid can be used for telemetry data and device lifecycle events. 但是,事件网格不能用于设备孪生更改事件和数字孪生体更改事件。But Event grid can not be used for device twin change events and digital twin change events.
中间件排序Ordering 是,事件顺序保持不变。Yes, ordering of events is maintained. 否,无法保证事件顺序。No, order of events is not guaranteed.
筛选Filtering 对消息应用程序属性、消息系统属性、消息正文、设备孪生标记和设备孪生属性执行的丰富筛选。Rich filtering on message application properties, message system properties, message body, device twin tags, and device twin properties. 筛选不会应用于数字孪生更改事件。Filtering isn't applied to digital twin change events. 有关示例,请参阅消息路由查询语法For examples, see Message Routing Query Syntax. 基于事件类型、使用者类型和每个事件中的属性进行筛选。Filtering based on event type, subject type and attributes in each event. 有关示例,请参阅了解在事件网格订阅中筛选事件For examples, see Understand filtering events in Event Grid Subscriptions. 订阅遥测事件时,在发布到事件网格之前,你可以对数据应用其他筛选器来基于你的 IoT 中心内的消息属性、消息正文和设备孪生进行筛选。When subscribing to telemetry events, you can apply additional filters on the data to filter on message properties, message body and device twin in your IoT Hub, before publishing to Event Grid. 请参阅如何筛选事件See how to filter events.
EndpointsEndpoints
  • 事件中心Event Hubs
  • Azure Blob 存储Azure Blob Storage
  • 服务总线队列Service Bus queue
  • 服务总线主题Service Bus topics

付费 IoT 中心 SKU(S1、S2 和 S3)限制为 10 个自定义终结点。Paid IoT Hub SKUs (S1, S2, and S3) are limited to 10 custom endpoints. 每个 IoT 中心都可创建 100 个路由。100 routes can be created per IoT Hub.
  • Azure FunctionsAzure Functions
  • Azure 自动化Azure Automation
  • 事件中心Event Hubs
  • 逻辑应用Logic Apps
  • 存储 BlobStorage Blob
  • 自定义主题Custom Topics
  • 队列存储Queue Storage
  • Microsoft FlowMicrosoft Flow
  • 通过 Webhook 的第三方服务Third-party services through WebHooks

每个 IoT 中心支持 500 个终结点。500 endpoints per IoT Hub are supported. 有关最新的终结点列表,请参阅事件网格事件处理程序For the most up-to-date list of endpoints, see Event Grid event handlers.
成本Cost 不会针对消息路由单独收费。There is no separate charge for message routing. 仅针对 IoT 中心的遥测数据入口收费。Only ingress of telemetry into IoT Hub is charged. 例如,如果将一条消息路由到三个不同终结点,则只收取一条消息的费用。For example, if you have a message routed to three different endpoints, you are billed for only one message. 不收取 IoT 中心费用。There is no charge from IoT Hub. 事件网格每月免费提供前 100,000 次操作,之后每百万次操作收取 0.60 美元。Event Grid offers the first 100,000 operations per month for free, and then $0.60 per million operations afterwards.

相似性Similarities

IoT 中心消息路由和事件网格也具有相似之处,其中一些详细信息如下表所示:IoT Hub message routing and Event Grid have similarities too, some of which are detailed in the following table:

功能Feature IoT 中心消息路由IoT Hub message routing IoT 中心与事件网格的集成IoT Hub integration with Event Grid
最大消息大小Maximum message size 256 KB,设备到云256 KB, device-to-cloud 256 KB,设备到云256 KB, device-to-cloud
可靠性Reliability 高:向终结点发送所有消息,每个路由至少一次。High: Delivers each message to the endpoint at least once for each route. 所有未在一小时内发送的消息都将过期。Expires all messages that are not delivered within one hour. 高:向 Webhook 发送所有消息,每个订阅至少一次。High: Delivers each message to the webhook at least once for each subscription. 所有未在 24 小时内发送的事件都将过期。Expires all events that are not delivered within 24 hours.
伸缩性Scalability 高:已经过优化,可支持数百万个同时连接的设备发送数十亿条消息。High: Optimized to support millions of simultaneously connected devices sending billions of messages. 高:每个区域每秒可路由 10,000,000 个事件。High: Capable of routing 10,000,000 events per second per region.
延迟Latency 低:准实时。Low: Near-real time. 低:准实时。Low: Near-real time.
发送到多个终结点Send to multiple endpoints 是,将一条消息发送到多个终结点。Yes, send a single message to multiple endpoints. 是,将一条消息发送到多个终结点。Yes, send a single message to multiple endpoints.
安全性Security Iot 中心提供每设备标识和可吊销的访问控制。Iot Hub provides per-device identity and revocable access control. 有关详细信息,请参阅 IoT 中心访问控制For more information, see the IoT Hub access control. 事件网格提供三点验证:事件订阅、事件发布和 Webhook 事件传送。Event Grid provides validation at three points: event subscriptions, event publishing, and webhook event delivery. 有关详细信息,请参阅事件网格安全性和身份验证For more information, see Event Grid security and authentication.

如何选择How to choose

IoT 中心消息路由和 IoT 中心与事件网格的集成通过执行不同的操作来实现类似结果。IoT Hub message routing and the IoT Hub integration with Event Grid perform different actions to achieve similar results. 它们均从 IoT 中心解决方案中获取信息并传递信息,以便其他服务可作出反应。They both take information from your IoT Hub solution and pass it on so that other services can react. 那么,如何决定使用哪一种?So how do you decide which one to use? 制定决策时,请思考以下问题:Consider the following questions to help guide your decision:

  • 要向终结点发送什么类型的数据?What kind of data are you sending to the endpoints?

    必须将遥测数据发送到其他服务时,请使用 IoT 中心消息路由。Use IoT Hub message routing when you have to send telemetry data to other services. 借助消息路由,还可以查询消息应用程序和系统属性、消息正文、设备孪生标记和设备孪生属性。Message routing also enables querying message application and system properties, message body, device twin tags, and device twin properties.

    IoT 中心与事件网格的集成可与 IoT 中心服务中发生的事件一起使用。The IoT Hub integration with Event Grid works with events that occur in the IoT Hub service. 这些 IoT 中心事件包括遥测数据,设备已创建、已删除、已连接和已断开连接。These IoT Hub events include telemetry data, device created, deleted, connected, and disconnected. 订阅遥测事件时,在发布到事件网格之前,你可以对数据应用其他筛选器来基于你的 IoT 中心内的消息属性、消息正文和设备孪生进行筛选。When subscribing to telemetry events, you can apply additional filters on the data to filter on message properties, message body and device twin in your IoT Hub, before publishing to Event Grid. 请参阅如何筛选事件See how to filter events.

  • 哪些终结点需要接收此信息?What endpoints need to receive this information?

    IoT 中心消息路由支持有限数量的终结点和终结点类型,但可构建连接器以将数据和事件重新路由到其他终结点。IoT Hub message routing supports limited number of unique endpoints and endpoint types, but you can build connectors to reroute the data and events to additional endpoints. 有关受支持终结点的完整列表,请参阅上节中的表。For a complete list of supported endpoints, see the table in the previous section.

    与事件网格的 IoT 中心集成支持每个 IoT 中心 500 个终结点和大量的终结点类型。The IoT Hub integration with Event Grid supports 500 endpoints per IoT Hub and a larger variety of endpoint types. 它本身集成了 Azure Functions、逻辑应用、存储和服务总线队列,并且还与 Webhook 配合使用,以便扩展向 Azure 服务生态系统外部发送数据以及将数据发送到第三方业务应用程序中。It natively integrates with Azure Functions, Logic Apps, Storage and Service Bus queues, and also works with webhooks to extend sending data outside of the Azure service ecosystem and into third-party business applications.

  • 数据按顺序到达是否重要?Does it matter if your data arrives in order?

    IoT 中心消息路由保持消息的发送顺序不变,以便其以相同顺序到达。IoT Hub message routing maintains the order in which messages are sent, so that they arrive in the same way.

    事件网格不保证终结点按照事件的发生顺序接收事件。Event Grid does not guarantee that endpoints will receive events in the same order that they occurred. 如果消息的绝对顺序至关重要,并/或使用者需要消息的可信唯一标识符,建议使用消息路由。For those cases in which absolute order of messages is significant and/or in which a consumer needs a trustworthy unique identifier for messages, we recommend using message routing.

后续步骤Next steps