Azure函数服务总线触发器并发

标签 azure azure-functions azureservicebus

我正在开发一个 Azure Function,该函数在 Dynamics 365 CRM 中执行多项操作。 我不完全理解 Azure Functions 并发的工作原理。 我有一个消费计划,我的 Azure 函数内部有一个由服务总线消息触发的函数。

当我第一次测试它时,服务总线收到大约 200 条消息,并且应用程序开始同时处理大量消息,向 Dynamics 365 发出大量无法处理的请求。 因此,在 Azure 门户中,我设法将最大实例数设置为 1,但该函数仍然一次处理许多消息。 对此设置限制的最佳方法是什么? 在 host.json 中使用 maxConcurrentCalls? 在 host.json 中使用 maxConcurrentSessions? 在应用配置中使用 WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT?

此外,将 maxConcurrentCalls 设置为 10 和 1 个函数实例或将其设置为 5 和 2 个函数实例有什么区别?

最佳答案

ma​​xConcurrentCalls 是在 host.json 中为 Azure Functions 服务总线触发器配置的属性。

默认情况下,Functions 的运行时会同时处理多个消息(默认值 - 16)。将 maxConcurrentCalls 设置为 1,以设置运行时一次仅处理单个队列或主题消息。

此外,maxConcurrentCalls 是最大数量。对每个缩放实例应启动的回调的并发调用数。

<小时/>

ma​​xConcurrentSessions - 每个缩放实例同时处理的最大 session 数。

This setting only applies for functions that receive a single message at a time.

对于每个实例一次只需要处理一条消息的要求,您可以在 host.json 中使用上述配置。

如果您的要求是函数单例支持,以确保一次只运行一个函数,那么您需要配置this .

<小时/>

WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT

此设置没有默认限制,它规定了最大数量。应用程序可以扩展到的实例数。

  1. 为了不横向扩展该函数并仅在一个实例中运行,请将 WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT 设置为 1
  2. 除了此设置之外,您还需要将 maxConcurrentCalls 设置为 1。

有关更多信息的引用文献:

  1. Azure Function to process only single message at one time
  2. Azure Functions - WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT and batchSize - how can I get the desired concurrency
  3. azure servicebus maxConcurrentCalls totally ignored
  4. Official documentation of host.json settings in Azure Function Service Bus Trigger explains about maxConcurrentCalls, maxConcurrentSessions
  5. Official Doc explains about WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT

关于Azure函数服务总线触发器并发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71578572/

相关文章:

azure - 安装模块-名称AzureAD-范围CurrentUser-Force

json - 在 Azure 数据工厂中使用嵌套 JSON 对象

c# - 如何在本地调试由EventGrid触发的Azure Function?

azure - 从异步的 azure 函数返回什么

azure-functions - v2 函数无法加载类型 'Microsoft.Azure.WebJobs.QueueTriggerAttribute'

azureservicebus - Azure 服务总线 session FIFO - 消费者应如何处理处理错误?

azure - 与 Azure 服务总线一起使用时获取 MassTransit.RequestTimeoutException

azure - 从 Azure 文件复制到 BLOB

dll - Azure 上的 RDLC 报告

size - 在 ServiceBus 上发送大消息的最佳实践