您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

Azure 事件网格中的事件处理程序Event handlers in Azure Event Grid

事件处理程序是发送事件的位置。An event handler is the place where the event is sent. 处理程序将执行一些进一步的操作来处理事件。The handler takes some further action to process the event. 会自动将多个 Azure 服务配置为处理事件。Several Azure services are automatically configured to handle events. 也可以使用任意 Webhook 来处理事件。You can also use any WebHook for handling events. Webhook 不需要托管在 Azure 中便可处理事件。The WebHook doesn't need to be hosted in Azure to handle events. 事件网格仅支持 HTTPS WebHook 终结点。Event Grid only supports HTTPS WebHook endpoints.

本文提供每个事件处理程序的内容的链接。This article provides links to content for each event handler.

Azure 自动化Azure Automation

使用 Azure 自动化通过自动化的 Runbook 来处理事件。Use Azure Automation to process events with automated runbooks.

标题Title 描述Description
教程:Azure 自动化与事件网格和 Microsoft TeamsTutorial: Azure Automation with Event Grid and Microsoft Teams 创建用于发送事件的虚拟机。Create a virtual machine, which sends an event. 此活动触发一个用于标记虚拟机的自动化 Runbook,并触发一条发送到 Microsoft Teams 频道的消息。The event triggers an Automation runbook that tags the virtual machine, and triggers a message that is sent to a Microsoft Teams channel.

Azure FunctionsAzure Functions

使用 Azure Functions 对事件进行无服务器响应。Use Azure Functions for serverless response to events.

使用 Azure Functions 作为处理程序时,请使用事件网格触发器而不是通用 HTTP 触发器。When using Azure Functions as the handler, use the Event Grid trigger instead of generic HTTP triggers. 事件网格会自动验证事件网格函数触发器。Event Grid automatically validates Event Grid Function triggers. 使用泛型 HTTP 触发器时,必须实现验证响应With generic HTTP triggers, you must implement the validation response.

标题Title 描述Description
Azure Functions 的事件网格触发器Event Grid trigger for Azure Functions 在 Functions 中使用事件网格触发器概述。Overview of using the Event Grid trigger in Functions.
教程:使用事件网格自动调整上传图像的大小Tutorial: automate resizing uploaded images using Event Grid 用户通过 Web 应用将映像上传到存储帐户。Users upload images through web app to storage account. 创建存储 Blob 后,事件网格会向用于重设已上传映像的大小的函数应用发送一个事件。When a storage blob is created, Event Grid sends an event to the function app, which resizes the uploaded image.
教程:将大数据流式传输到数据仓库Tutorial: stream big data into a data warehouse 当事件中心创建捕获文件时,事件网格会将一个事件发送到函数应用。When Event Hubs creates a Capture file, Event Grid sends an event to a function app. 应用会检索捕获文件并将数据迁移到数据仓库。The app retrieves the Capture file and migrates data to a data warehouse.
教程:Azure 服务总线到 Azure 事件网格集成示例Tutorial: Azure Service Bus to Azure Event Grid integration examples 事件网格将消息从服务总线主题发送到函数应用和逻辑应用。Event Grid sends messages from Service Bus topic to function app and logic app.

事件中心Event Hubs

如果解决方案获取事件的速度快于处理事件的速度,请使用事件中心。Use Event Hubs when your solution gets events faster than it can process the events. 应用程序按照自己的计划处理来自事件中心的事件。Your application processes the events from Event Hubs at it own schedule. 可以通过缩放事件处理来处理传入的事件。You can scale your event processing to handle the incoming events.

事件中心可以充当事件源或事件处理程序。Event Hubs can act as either an event source or event handler. 以下文章展示了如何将事件中心用作处理程序。The following article shows how to use Event Hubs as a handler.

标题Title 描述Description
快速入门:使用 Azure CLI 和事件网格将自定义事件路由到 Azure 事件中心Quickstart: route custom events to Azure Event Hubs with Azure CLI and Event Grid 将自定义事件发送到事件中心以供应用程序处理。Sends a custom event to an event hub for processing by an application.
资源管理器模板:自定义主题和事件中心终结点Resource Manager template: custom topic and Event Hubs endpoint 用于创建自定义主题的订阅的资源管理器模板。A Resource Manager template that creates a subscription for a custom topic. 它将事件发送到 Azure 事件中心。It sends events to an Azure Event Hubs.

有关事件中心用作源的示例,请参阅事件中心源For examples of Event Hubs as a source, see Event Hubs source.

混合连接Hybrid Connections

使用 Azure 中继混合连接将事件发送到企业网络内没有可公开访问的终结点的应用程序。Use Azure Relay Hybrid Connections to send events to applications that are within an enterprise network and don't have a publicly accessible endpoint.

标题Title 描述Description
教程:将事件发送到混合连接Tutorial: send events to hybrid connection 将自定义事件发送到现有混合连接以供侦听器应用程序处理。Sends a custom event to an existing hybrid connection for processing by a listener application.

逻辑应用Logic Apps

使用逻辑应用自动执行事件响应业务流程。Use Logic Apps to automate business processes for responding to events.

标题Title 描述Description
教程:通过 Azure 事件网格和逻辑应用监视虚拟机更改Tutorial: monitor virtual machine changes with Azure Event Grid and Logic Apps 逻辑应用可监视对虚拟机的更改并就这些更改发送电子邮件。A logic app monitors changes to a virtual machine and sends emails about those changes.
教程:使用逻辑应用发送有关 Azure IoT 中心事件的电子邮件Tutorial: send email notifications about Azure IoT Hub events using Logic Apps 每次将设备添加到 IoT 中心时,逻辑应用就会发送一封通知电子邮件。A logic app sends a notification email every time a device is added to your IoT hub.
教程:Azure 服务总线到 Azure 事件网格集成示例Tutorial: Azure Service Bus to Azure Event Grid integration examples 事件网格将消息从服务总线主题发送到函数应用和逻辑应用。Event Grid sends messages from Service Bus topic to function app and logic app.

服务总线队列 (预览版)Service Bus Queue (Preview)

使用 Service Bus 作为事件处理程序用于将您的事件中事件网格路由直接向服务总线队列用于企业应用程序中的缓冲或命令和控制方案。Use Service Bus as an event handler to route your events in Event Grid directly to Service Bus queues for use in buffering or command and control scenarios in enterprise applications. 在预览并不适用于服务总线主题和会话,但适用于所有层的服务总线队列。The preview does not work with Service Bus Topics and Sessions, but it does work with all tiers of Service Bus queues.

请注意,服务总线时如处理程序是在公共预览版中,您必须安装 CLI 或 PowerShell 扩展时使用这些凭据创建事件订阅。Please note, while Service Bus as a handler is in public preview, you must install the CLI or PowerShell extension when using those to create event subscriptions.

安装适用于 Azure CLI 的扩展Install extension for Azure CLI

对于 Azure CLI,需要事件网格扩展For Azure CLI, you need the Event Grid extension.

CloudShell 中:In CloudShell:

  • 如果您以前安装扩展,将其与更新az extension update -n eventgridIf you've installed the extension previously, update it with az extension update -n eventgrid.
  • 如果你以前尚未安装该扩展,安装使用az extension add -n eventgridIf you haven't installed the extension previously, install it by using az extension add -n eventgrid.

对于本地安装:For a local installation:

  1. 安装 Azure CLIInstall the Azure CLI. 请确保通过检查与具有最新版本, az --versionMake sure that you have the latest version, by checking with az --version.
  2. 卸载早期版本的扩展的az extension remove -n eventgridUninstall previous versions of the extension with az extension remove -n eventgrid.
  3. 安装eventgrid扩展名az extension add -n eventgridInstall the eventgrid extension with az extension add -n eventgrid.

安装适用于 PowerShell 的模块Install module for PowerShell

对于 PowerShell,需要 AzureRM.EventGrid 模块For PowerShell, you need the AzureRM.EventGrid module.

CloudShell 中:In CloudShell:

  • 安装的模块Install-Module -Name AzureRM.EventGrid -AllowPrerelease -Force -Repository PSGalleryInstall the module with Install-Module -Name AzureRM.EventGrid -AllowPrerelease -Force -Repository PSGallery.

对于本地安装:For a local installation:

  1. 以管理员身份打开 PowerShell 控制台。Open PowerShell console as administrator.
  2. 安装的模块Install-Module -Name AzureRM.EventGrid -AllowPrerelease -Force -Repository PSGalleryInstall the module with Install-Module -Name AzureRM.EventGrid -AllowPrerelease -Force -Repository PSGallery.

如果 -AllowPrerelease 参数不可用,请使用以下步骤:If the -AllowPrerelease parameter isn't available, use the following steps:

  1. 运行 Install-Module PowerShellGet -ForceRun Install-Module PowerShellGet -Force.
  2. 运行 Update-Module PowerShellGetRun Update-Module PowerShellGet.
  3. 关闭 PowerShell 控制台。Close the PowerShell console.
  4. 以管理员身份重新启动 PowerShell。Restart PowerShell as administrator.
  5. 安装模块Install-Module -Name AzureRM.EventGrid -AllowPrerelease -Force -Repository PSGalleryInstall the module Install-Module -Name AzureRM.EventGrid -AllowPrerelease -Force -Repository PSGallery.

使用 CLI 添加服务总线处理程序Using CLI to add a Service Bus handler

有关 Azure CLI,下面的示例订阅,并连接到服务总线队列的事件网格主题:For Azure CLI, the following example subscribes and connects an Event Grid topic to a Service Bus queue:

# If you haven't already installed the extension, do it now.
# This extension is required for preview features.
az extension add --name eventgrid

az eventgrid event-subscription create \
    --name <my-event-subscription> \
    --source-resource-id /subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.EventGrid/topics/topic1 \
    --endpoint-type servicebusqueue \
    --endpoint /subscriptions/{SubID}/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ns1/queues/queue1

队列存储Queue Storage

使用队列存储接收需拉取的事件。Use Queue storage to receive events that need to be pulled. 如果正在运行的进程需要很长时间才能响应,可能会使用队列存储。You might use Queue storage when you have a long running process that takes too long to respond. 通过向队列存储发送事件,应用程序可以按照自己的计划拉取和处理事件。By sending events to Queue storage, the app can pull and process events on its own schedule.

标题Title 描述Description
快速入门:使用 Azure CLI 和事件网格将自定义事件路由到 Azure 队列存储Quickstart: route custom events to Azure Queue storage with Azure CLI and Event Grid 说明如何将自定义事件发送到队列存储。Describes how to send custom events to a Queue storage.

WebhookWebHooks

将 Webhook 用于可响应事件的可自定义终结点。Use webhooks for customizable endpoints that respond to events.

标题Title 描述Description
快速入门:使用 Azure CLIPowerShell门户创建和路由自定义事件。Quickstart: create and route custom events with - Azure CLI, PowerShell, and portal. 展示了如何将自定义事件发送到 WebHook。Shows how to send custom events to a WebHook.
快速入门:使用 Azure CLIPowerShell门户将 Blob 存储事件路由到自定义 Web 终结点。Quickstart: route Blob storage events to a custom web endpoint with - Azure CLI, PowerShell, and portal. 展示了如何将 Blob 存储事件发送到 WebHook。Shows how to send blob storage events to a WebHook.
快速入门:发送容器注册表事件Quickstart: send container registry events 展示了如何使用 Azure CLI 发送容器注册表事件。Shows how to use Azure CLI to send Container Registry events.
概述:将事件接收到 HTTP 终结点Overview: receive events to an HTTP endpoint 介绍如何验证 HTTP 终结点以接收来自事件订阅的事件,然后接收和反序列化事件。Describes how to validate an HTTP endpoint to receive events from an Event Subscription, and receive and deserialize events.

后续步骤Next steps