简体   繁体   English

Azure功能的事件中心输入绑定

[英]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: 我只想添加以下内容:

  1. If you use the default EventHub-Trigger C# template, the Function created will process 1 message per execution. 如果使用默认的EventHub-Trigger C#模板,则创建的函数每次执行将处理1条消息。

  1. 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 } }

  2. 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: 附加评论:

  1. Under the Consumption Plan, a Function is currently allowed a max default 5-minute execution time (configurable up to 10 mins --Added on 11/30/2017) . 根据《消费计划》,当前允许一个功能的 最大 默认执行时间为5分钟(最多可配置10分钟-在2017年11月30日添加) You should experiment with the maxBatchSize and prefetchCount setting to ensure that a typical execution of the batch will complete within the timeframe. 您应该尝试使用maxBatchSizeprefetchCount设置来确保批处理的典型执行将在该时间范围内完成。

  1. The prefetchCount should be 3-4 times the maxBatchSize . prefetchCount应该是maxBatchSize的 3-4倍。

  1. Each Function host instance is backed by a single EventProcessorHost (EPH). 每个功能主机实例均由单个EventProcessorHost(EPH)支持。 EPH uses a checkpointing mechanism to mark the last successfully processed message. EPH使用检查点机制来标记最后成功处理的消息。 A Function execution could terminate prematurely due to uncaught exceptions in the Function code host crashing, timeout or partition lease lost, resulting in an unsuccessful checkpoint. 由于函数代码主机中未捕获的异常崩溃,超时或分区租约丢失,导致检查点未成功,导致函数执行可能过早终止。 When the Function execution restarts again, the batch retrieved will have messages from the last known checkpoint. 当功能执行再次重新启动时,检索到的批处理将包含来自最后一个已知检查点的消息。 Setting a very high value for maxBatchSize will also mean that you must re-process a large batch. 为maxBatchSize设置一个很高的值也将意味着您必须重新处理一个大批处理。 EventHub guarantees at-least-once delivery but not at-most-once delivery. EventHub保证至少一次交付,但不保证一次交付。 Azure Functions will not attempt to change that behavior. Azure Functions不会尝试更改该行为。 If having only unique messages is a priority, you will need to handle de-duplication in your downstream workflows. 如果只有唯一消息是优先事项,则您将需要在下游工作流中处理重复数据删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM