Azure Functions 作为事件网格事件的事件处理程序Azure function as an event handler for Event Grid events

事件处理程序是发送事件的位置。An event handler is the place where the event is sent. 处理程序将通过一个操作来处理事件。The handler takes an action to process the event. 几个 Azure 服务已自动配置为处理事件,Azure Functions 就是其中之一。Several Azure services are automatically configured to handle events and Azure Functions is one of them.

在无服务器体系结构中使用 Azure Functions 响应事件网格中的事件。Use Azure Functions in a serverless architecture to respond to events from Event Grid. 使用 Azure Functions 作为处理程序时,请使用事件网格触发器而不是通用 HTTP 触发器。When using an Azure function as the handler, use the Event Grid trigger instead of the generic HTTP trigger. 事件网格会自动验证事件网格触发器。Event Grid automatically validates Event Grid triggers. 使用通用 HTTP 触发器时,必须自行实现验证响应With generic HTTP triggers, you must implement the validation response yourself.

有关详细信息,请参阅 Azure Functions 的事件网格触发器,概要了解如何在函数中使用事件网格触发器。For more information, see Event Grid trigger for Azure Functions for an overview of using the Event Grid trigger in functions.

教程Tutorials

标题Title 说明Description
快速入门:使用函数处理事件Quickstart: Handle events with function 将自定义事件发送到函数进行处理。Sends a custom event to a function for processing.
教程:使用事件网格自动调整上传图像的大小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 a function app and a logic app.

REST 示例(对于 PUT)REST example (for PUT)

{
    "properties": 
    {
        "destination": 
        {
            "endpointType": "AzureFunction",
            "properties": 
            {
                "resourceId": "/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.Web/sites/<FUNCTION APP NAME>/functions/<FUNCTION NAME>",
                "maxEventsPerBatch": 1,
                "preferredBatchSizeInKilobytes": 64
            }
        },
        "eventDeliverySchema": "EventGridSchema"
    }
}

后续步骤Next steps

如需支持的事件处理程序的列表,请参阅事件处理程序一文。See the Event handlers article for a list of supported event handlers.