从 Azure 流分析输出的 Azure FunctionsAzure Functions output from Azure Stream Analytics

Azure Functions 是一个无服务器计算服务,可以使用它按需运行代码,而无需显式预配或管理基础结构。Azure Functions is a serverless compute service that you can use to run code on-demand without having to explicitly provision or manage infrastructure. 它允许实现由 Azure 或合作伙伴服务中出现的事件所触发的代码。It lets you implement code that's triggered by events occurring in Azure or partner services. Azure Functions 响应触发的这一功能使其成为 Azure 流分析的自然输出。This ability of Azure Functions to respond to triggers makes it a natural output for Azure Stream Analytics. 此输出适配器允许用户将流分析连接到 Azure Functions,并运行脚本或一段代码来响应各种事件。This output adapter enables users to connect Stream Analytics to Azure Functions, and run a script or piece of code in response to a variety of events.

也不支持从多租户群集中运行的流分析作业连接到虚拟网络 (VNet) 内的 Azure Functions。Connection to Azure Functions inside a virtual network (VNet) from an Stream Analytics job that is running in a multi-tenant cluster is also not supported.

Azure 流分析通过 HTTP 触发器调用 Azure Functions。Azure Stream Analytics invokes Azure Functions via HTTP triggers. 提供具有以下可配置属性的 Azure Functions 输出适配器:The Azure Functions output adapter is available with the following configurable properties:

属性名称Property name 说明Description
函数应用Function app Azure Functions 应用的名称。The name of your Azure Functions app.
函数Function Azure Functions 应用中的函数的名称。The name of the function in your Azure Functions app.
Key 若要使用其他订阅中的 Azure 函数,可提供用于访问该函数的密钥。If you want to use an Azure Function from another subscription, you can do so by providing the key to access your function.
最大批大小Max batch size 此属性可用于设置将发送到 Azure 函数的每个输出批的最大大小。A property that lets you set the maximum size for each output batch that's sent to your Azure function. 输入单元以字节为单位。The input unit is in bytes. 默认情况下,此值为 262,144 字节 (256 KB)。By default, this value is 262,144 bytes (256 KB).
最大批数Max batch count 一个用于指定发送到 Azure Functions 的每个批中的最大事件数的属性。A property that lets you specify the maximum number of events in each batch that's sent to Azure Functions. 默认值为 100。The default value is 100.

对于已成功处理的批,Azure 流分析预期函数应用中的 HTTP 状态为 200。Azure Stream Analytics expects HTTP status 200 from the Functions app for batches that were processed successfully.

当 Azure 流分析从 Azure 函数中收到 413(“http 请求实体过大”)异常时,它将减小发送到 Azure Functions 的批的大小。When Azure Stream Analytics receives a 413 ("http Request Entity Too Large") exception from an Azure function, it reduces the size of the batches that it sends to Azure Functions. 在 Azure 函数代码中,使用此异常以确保 Azure 流分析不会发送过大的批。In your Azure function code, use this exception to make sure that Azure Stream Analytics doesn't send oversized batches. 此外,确保函数中使用的最大批数和最大批大小值与在流分析门户中输入的值一致。Also, make sure that the maximum batch count and size values used in the function are consistent with the values entered in the Stream Analytics portal.

备注

在测试连接过程中,流分析会将空批发送到 Azure Functions,以测试两者之间的连接是否正常。During test connection, Stream Analytics sends an empty batch to Azure Functions to test if the connection between the two works. 确保 Functions 应用处理空批请求,以确保通过连接测试。Make sure that your Functions app handles empty batch requests to make sure test connection passes.

另外,如果时间窗口中没有任何事件登录,则不生成任何输出。Also, in a situation where there's no event landing in a time window, no output is generated. 因此,不会调用 computeResult 函数。As a result, the computeResult function isn't called. 此行为与内置窗口化聚合函数一致。This behavior is consistent with the built-in windowed aggregate functions.

分区Partitioning

分区键基于查询中的 PARTITION BY 子句。The partition key is based on the PARTITION BY clause in the query. 输出编写器的数量与完全并行化的查询的输入分区一致。The number of output writers follows the input partitioning for fully parallelized queries.

输出批大小Output batch size

默认批大小为 262,144 字节 (256 KB)。The default batch size is 262,144 bytes (256 KB). 每批的默认事件计数为 100。The default event count per batch is 100. 批大小是可配置的,可在流分析输出选项中增大或减小。The batch size is configurable and can be increased or decreased in the Stream Analytics output options.

后续步骤Next steps