選擇 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 GridEvent 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 GridEvent Grid

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.

Event Grid 不僅與 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. Event Grid 有效且可靠地從 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. 可以使用 Event Grid 來回應其他服務中的事件。You use Event Grid to respond to events in the other services. 如需使用 Event Grid 與事件中樞將資料移轉至資料倉儲的範例,請參閱將巨量資料串流至資料倉儲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: