Event Hub input binding for Azure Functions

眉间皱痕 提交于 2019-12-06 22:26:26

@Mikhail is correct. 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.

  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.

    b. In run.csx, modify Function signature and process messages in a loop, e.g.,

    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.

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). You should experiment with the maxBatchSize and prefetchCount setting to ensure that a typical execution of the batch will complete within the timeframe.

  1. The prefetchCount should be 3-4 times the maxBatchSize.

  1. Each Function host instance is backed by a single EventProcessorHost (EPH). EPH uses a checkpointing mechanism to mark the last successfully processed message. 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. EventHub guarantees at-least-once delivery but not at-most-once delivery. Azure Functions will not attempt to change that behavior. If having only unique messages is a priority, you will need to handle de-duplication in your downstream workflows.

By default it's going to be 1 by 1 processing, but you can do batches too. 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!