[英]Event Hub input binding for Azure Functions
I have an Azure Function with an input binding to an Event Hub. 我有一个Azure函数,其输入绑定到事件中心。
public static async Task Run(TraceWriter log, string eventHubMessage)
When the function is triggered, how many messages does it receive per execution by default? 触发该函数后,默认情况下每次执行它会收到多少消息?
Is it 1 execution = 1 message? 是1执行= 1消息吗?
I have read the documentation and understand you can set these properties in the function's host.json file: 我已经阅读了文档,并了解可以在函数的host.json文件中设置以下属性:
"eventHub": {
// The maximum event count received per receive loop. The default is 64.
"maxBatchSize": 64,
// The default PrefetchCount that will be used by the underlying EventProcessorHost.
"prefetchCount": 256
}
Does maxBatchSize mean I will receive 64 messages in 1 execution? maxBatchSize是否意味着我将在1次执行中收到64条消息?
By default it's going to be 1 by 1 processing, but you can do batches too. 默认情况下它将是1比1处理,但是您也可以批量处理。 Change the signature of your function to
将函数的签名更改为
public static async Task Run(TraceWriter log, string[] eventHubMessages)
(if you change the name like I did, rename the binding parameter too) (如果像我一样更改名称,也要重命名绑定参数)
Reference github issue . 参考github问题 。
@Mikhail is correct. @Mikhail是正确的。 I'd just like to add the following:
我只想添加以下内容:
If you need each execution to process in batches, change the following: 如果您需要每次执行来批量处理,请更改以下内容:
a. 一种。 In
function.json
, add the property "cardinality":"many"
as shown here . 在
function.json
,添加属性"cardinality":"many"
如图所示这里 。
b. b。 In
run.csx
, modify Function signature and process messages in a loop, eg, 在
run.csx
,修改功能签名并循环处理消息,例如,
public static async Task Run(TraceWriter log, string[] eventHubMessages) { foreach(string message in eventHubMessages) { // process messages } }
The host.json configuration you specified in the question allows you to experiment with the correct batch size and prefetch buffer to meet the needs of your workflow. 通过在问题中指定的host.json配置,您可以尝试使用正确的批处理大小和预取缓冲区来满足工作流程的需求。
Additional comments: 附加评论:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.