在 Azure 消息传递服务之间进行选择 - 事件网格、事件中心和服务总线Choose between Azure messaging services - Event Grid, Event Hubs, and Service Bus

Azure 提供三种协助在整个解决方案中传递事件消息的服务。Azure offers three services that assist with delivering event messages throughout a solution. 这些服务分别为:These services are:

虽然它们有一些相似之处,但是每种服务都旨在针对特定的场景。Although they have some similarities, each service is designed for particular scenarios. 本文介绍这些服务之间的区别,并帮助你选择最适合你应用程序的服务。This article describes the differences between these services, and helps you understand which one to choose for your application. 在许多情况下,消息传递服务是互补的,可以一同使用。In many cases, the messaging services are complementary and can be used together.

事件与消息服务Event vs. message services

传递事件的服务与传递消息的服务之间有一个需要注意的重要区别。There's an important distinction to note between services that deliver an event and services that deliver a message.

事件Event

事件是条件或状态更改的轻量通知。An event is a lightweight notification of a condition or a state change. 事件发布者对于如何处理事件没有期望。The publisher of the event has no expectation about how the event is handled. 事件使用者决定要对通知执行的操作。The consumer of the event decides what to do with the notification. 事件可以是离散单元或一系列的一部分。Events can be discrete units or part of a series.

离散事件报告状态更改,并可操作。Discrete events report state change and are actionable. 若要执行下一步,使用者只需知道发生了问题。To take the next step, the consumer only needs to know that something happened. 事件数据包含关于所发生事件的信息,但不包含触发事件的数据。The event data has information about what happened but doesn't have the data that triggered the event. 例如,事件会通知使用者文件已创建。For example, an event notifies consumers that a file was created. 它可能包含文件的常规信息,但不包含文件本身。It may have general information about the file, but it doesn't have the file itself. 离散事件非常适合于需要缩放的无服务器解决方案。Discrete events are ideal for serverless solutions that need to scale.

系列事件报告情况,并且可分析。Series events report a condition and are analyzable. 事件按时间排序并彼此相关。The events are time-ordered and interrelated. 使用者需要排序的一系列事件以分析发生的情况。The consumer needs the sequenced series of events to analyze what happened.

消息Message

消息是由将使用的服务生成或存储在其他位置的原始数据。A message is raw data produced by a service to be consumed or stored elsewhere. 消息包含触发消息管道的数据。The message contains the data that triggered the message pipeline. 消息发布者对于使用者如何处理消息有期望。The publisher of the message has an expectation about how the consumer handles the message. 双方之间存在协定。A contract exists between the two sides. 例如,发布者发送一条包含原始数据的消息,并期望使用者基于该数据创建文件且在工作完成后发送响应。For example, the publisher sends a message with the raw data, and expects the consumer to create a file from that data and send a response when the work is done.

服务对比Comparison of services

服务Service 目的Purpose 类型Type 何时使用When to use
事件网格Event Grid 反应编程Reactive programming 事件分发(离散)Event distribution (discrete) 对状态更改做出响应React to status changes
事件中心Event Hubs 大数据管道Big data pipeline 事件流式处理(系列)Event streaming (series) 遥测数据和分布式数据流式处理Telemetry and distributed data streaming
服务总线Service Bus 高价值企业消息传递High-value enterprise messaging 消息Message 订单处理和财务交易Order processing and financial transactions

事件网格Event Grid

事件网格是启用事件驱动、反应编程的事件底板。Event Grid is an eventing backplane that enables event-driven, reactive programming. 它使用发布-订阅模式。It uses a publish-subscribe model. 发布服务器发出事件,但不知道处理哪些事件。Publishers emit events, but have no expectation about which events are handled. 订阅服务器决定需要处理的事件。Subscribers decide which events they want to handle.

事件网格与 Azure 服务深度集成,并可与第三方服务集成。Event Grid is deeply integrated with Azure services and can be integrated with third-party services. 它简化事件消耗,并通过消除不断的轮询需求降低成本。It simplifies event consumption and lowers costs by eliminating the need for constant polling. 事件网格高效可靠地路由来自 Azure 和非 Azure 资源的事件。Event Grid efficiently and reliably routes events from Azure and non-Azure resources. 它将事件分布到注册的订阅服务器终结点。It distributes the events to registered subscriber endpoints. 事件消息包含对服务和应用程序中的更改做出响应所需的信息。The event message has the information you need to react to changes in services and applications. 事件网格不是数据管道,并且不提供已更新的实际对象。Event Grid isn't a data pipeline, and doesn't deliver the actual object that was updated.

对于不提交到终结点的事件,事件网格支持死信功能。Event Grid supports dead-lettering for events that aren't delivered to an endpoint.

它具有以下特征:It has the following characteristics:

  • 动态可缩放dynamically scalable
  • 低成本low cost
  • 无服务器serverless
  • “至少一次”交付at least once delivery

事件中心Event Hubs

Azure 事件中心是大数据管道。Azure Event Hubs is a big data pipeline. 它促进遥测数据和事件流数据的捕获、保留和重播。It facilitates the capture, retention, and replay of telemetry and event stream data. 数据可能来自多个并发源。The data can come from many concurrent sources. 事件中心允许提供遥测数据和事件数据给多种流式处理基础结构和分析服务。Event Hubs allows telemetry and event data to be made available to a variety of stream-processing infrastructures and analytics services. 它作为数据流或捆绑事件批提供。It is available either as data streams or bundled event batches. 此服务提供一种可实现快速数据检索以进行实时处理及重复重播所存储原始数据的解决方案。This service provides a single solution that enables rapid data retrieval for real-time processing as well as repeated replay of stored raw data. 可以将流数据捕获到一个文件中以进行处理和分析。It can capture the streaming data into a file for processing and analysis.

它具有以下特征:It has the following characteristics:

  • 低延迟low latency
  • 每秒可以接收和处理数百万的事件capable of receiving and processing millions of events per second
  • “至少一次”交付at least once delivery

服务总线Service Bus

服务总线适用于传统企业应用程序。Service Bus is intended for traditional enterprise applications. 这些企业应用程序需要事务、排序、重复检测和即时一致性。These enterprise applications require transactions, ordering, duplicate detection, and instantaneous consistency. 服务总线使得云原生应用程序能够为业务进程提供可靠的状态转换管理。Service Bus enables cloud-native applications to provide reliable state transition management for business processes. 处理不能丢失或复制的高价值消息时,请使用 Azure 服务总线。When handling high-value messages that cannot be lost or duplicated, use Azure Service Bus. 服务总线还利于跨混合云解决方案的高度安全通信,并且可以将现有本地系统连接到云解决方案。Service Bus also facilitates highly secure communication across hybrid cloud solutions and can connect existing on-premises systems to cloud solutions.

服务总线是一个中转消息传送系统。Service Bus is a brokered messaging system. 它将消息存储在“中转站”(例如队列)中,直到使用方准备好接收这些消息。It stores messages in a "broker" (for example, a queue) until the consuming party is ready to receive the messages.

它具有以下特征:It has the following characteristics:

  • 需要轮询的可靠异步消息传递(企业消息传递作为服务)reliable asynchronous message delivery (enterprise messaging as a service) that requires polling
  • 高级消息传递功能,例如,FIFO、批处理/会话、事务、死信、时态控制、路由和筛选以及重复检测advanced messaging features like FIFO, batching/sessions, transactions, dead-lettering, temporal control, routing and filtering, and duplicate detection
  • “至少一次”交付at least once delivery
  • 可选的按序交付optional in-order delivery

同时使用多种服务Use the services together

在某些情况下,可同时使用多种服务满足不同的角色。In some cases, you use the services side by side to fulfill distinct roles. 例如,电子商务网站可以使用服务总线处理订单,使用事件中心捕获站点遥测数据,使用事件网格响应事件(例如商品已发货)。For example, an e-commerce site can use Service Bus to process the order, Event Hubs to capture site telemetry, and Event Grid to respond to events like an item was shipped.

在其他情况下,可将它们链接在一起以形成事件和数据管道。In other cases, you link them together to form an event and data pipeline. 使用事件网格可响应其他服务中的事件。You use Event Grid to respond to events in the other services. 有关结合使用事件网格和事件中心以将数据迁移到数据仓库的实例,请参阅将大数据流式传输到数据仓库For an example of using Event Grid with Event Hubs to migrate data to a data warehouse, see Stream big data into a data warehouse. 下图显示流式处理数据的工作流。The following image shows the workflow for streaming the data.

流数据概述

后续步骤Next steps

请参阅以下文章:See the following articles: