Azure函数: Limiting number of concurrant Service Bus messages

标签 azure azure-functions azureservicebus

我正在开发一个 Azure 函数,该函数从基于 session 的服务总线主题触发并通过 API 请求将数据发送到 CRM 系统。 CRM的API有使用和负载保护限制,我们可能会在短时间内收到大量消息,所以我正在寻找最好的方法来限制该功能。

我认为 host.json 中的 maxConcurrentSessions 设置可能对我有帮助,我可以将其限制为一次大约 20 条消息。我还可以查看功能应用程序中的“强制扩展限制”,但我想这不一定会限制一次处理的消息数量。 maxConcurrentSessions 是最佳设置吗?还是还有其他考虑因素?

另一种方法(可能除了上述方法之外)是在达到 API 限制后的一段时间内“暂停”或停止该函数接收更多消息。有谁知道是否可以以编程方式实时暂停 Azure 函数的执行,或阻止它接收更多消息?

最佳答案

I'm thinking the maxConcurrentSessions setting in the host.json might help me, I could limit it to around 20 messages at a time. I could also look at the "Enforce Scale Out Limit" in the Function App, but I guess that wouldn't necessarily limit the number of messages processed at one time. Would maxConcurrentSessions be the best setting to go for, or are there other considerations?

您可以使用 maxConcurrentCalls 来限制消息泵应启动的回调并发调用的最大数量。默认情况下,Functions 运行时会同时处理多个消息。如果设置为 1,它将一次仅处理单个队列或主题消息。

结构如下:

{
    "version": "2.0",
    "extensions": {
        "serviceBus": {
            "prefetchCount": 100,
            "messageHandlerOptions": {
                "autoComplete": true,
                "maxConcurrentCalls": 1,
                "maxAutoRenewDuration": "00:05:00"
            },
            "sessionHandlerOptions": {
                "autoComplete": true,
                "messageWaitTimeout": "00:00:30",
                "maxAutoRenewDuration": "00:55:00",
                "maxConcurrentSessions": 1
            }
        }
    }
}

同时,您可以将Maximum Scale Out Limit 设置为较小的值,以防止高负载下功能扩展。

关于Azure函数: Limiting number of concurrant Service Bus messages,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65766558/

相关文章:

azure - 了解 Kusto

azure - 由于存储帐户错误,无法打开 Cloud Shell

c# - 多个异步 Cosmos DB 查询导致 "InvalidCastExceptions"

当使用 NLog 更新文件时,Azure Blob 触发器函数仅触发一次

c# - 如何在Azure Function的HttpTrigger中使用Authorize属性

c# - 创建带有心跳的任务

c# - Azure 服务总线中继安全

azure - 更新 azure api 管理服务的位置时出错

c# - 访问 Azure Service Fabric 有状态服务状态

Azure 服务总线多个 QueueClient