Azure功能的事件中心输入绑定 [英] Event Hub input binding for Azure Functions

查看:58
本文介绍了Azure功能的事件中心输入绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Azure函数,其输入绑定到事件中心.

I have an Azure Function with an input binding to an Event Hub.

public static async Task Run(TraceWriter log, string eventHubMessage)

该功能被触发时,默认情况下每次执行会收到多少条消息?

When the function is triggered, how many messages does it receive per execution by default?

是1次执行= 1条消息吗?

Is it 1 execution = 1 message?

我已阅读文档并了解您可以在函数的host.json文件中设置以下属性:

I have read the documentation and understand you can set these properties in the function's host.json file:

"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
}

maxBatchSize是否意味着我将在1次执行中收到64条消息?

Does maxBatchSize mean I will receive 64 messages in 1 execution?

推荐答案

@Mikhail是正确的.我只想添加以下内容:

@Mikhail is correct. I'd just like to add the following:

  1. 如果您使用默认的EventHub-Trigger C#模板,则创建的函数每次执行将处理1条消息.

  1. 如果您需要每次执行都要分批处理,请更改以下内容:

  1. If you need each execution to process in batches, change the following:

a.在function.json中,添加属性"cardinality":"many",如下所示:此处.

a. In function.json, add the property "cardinality":"many" as shown here.

b.在run.csx中,修改功能签名并循环处理消息,例如

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

public static async Task Run(TraceWriter log, string[] eventHubMessages) { foreach(string message in eventHubMessages) { // process messages } }

通过在问题中指定的host.json配置,您可以尝试使用正确的批处理大小和预取缓冲区来满足工作流程的需求.

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.

其他评论:

  1. 根据消费计划,当前允许某个功能 max 默认5分钟执行时间(最多可配置10分钟-2017年11月30日添加).您应该尝试使用 maxBatchSize prefetchCount 设置,以确保典型的批处理执行将在时间范围内完成.
  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. prefetchCount 应该是 maxBatchSize 的3-4倍.
  1. The prefetchCount should be 3-4 times the maxBatchSize.

  1. 每个功能主机实例由单个EventProcessorHost(EPH)支持. EPH使用检查点机制来标记最后成功处理的消息.由于功能代码中的未捕获的异常主机崩溃,超时或分区租约丢失,从而导致检查点失败,因此功能执行可能过早终止.当功能执行再次重新启动时,检索到的批处理将包含来自最后一个已知检查点的消息.为maxBatchSize设置一个很高的值也将意味着您必须重新处理一个大批处理. EventHub保证至少一次交付,但不保证一次交付. Azure Functions不会尝试更改该行为.如果只有唯一消息是优先事项,则您将需要在下游工作流程中处理重复数据删除.
  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.

这篇关于Azure功能的事件中心输入绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆