首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Azure函数:限制每秒调用的次数

Azure函数:限制每秒调用的次数
EN

Stack Overflow用户
提问于 2018-03-17 18:07:40
回答 4查看 6.7K关注 0票数 8

我有一个由队列消息触发的Azure函数。该函数向第三方API发出请求.不幸的是,这个API有限制-10个事务每秒,但我可能有超过10条消息每秒服务总线队列。如何限制Azure函数的调用次数以满足第三方API的限制?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2018-03-17 19:04:54

不幸的是,在这方面没有内置的选择。

限制并发执行的唯一可靠方法是在固定的(而不是消费计划)上运行,只需要始终运行一个实例。你得为此付出代价。

然后在host.json文件中设置该选项:

代码语言:javascript
复制
"serviceBus": {
    // The maximum number of concurrent calls to the callback the message
    // pump should initiate. The default is 16.
    "maxConcurrentCalls": 10
}

最后,确保您的函数执行(或其他最小持续时间,并相应地调整并发调用)。

正如@SeanFeldman所建议的,请参阅this answer中的其他一些想法。它是关于存储队列的,但也适用于服务总线。

票数 5
EN

Stack Overflow用户

发布于 2018-03-17 18:50:44

您可以尝试编写一些自定义逻辑,即在Azure函数中实现自己的内存中队列,以排队处理请求,并限制对第三方API的调用。无论如何,在调用第三方API成功之前,您不需要确认队列中的消息。这样,可靠性也得到了保持。

票数 0
EN

Stack Overflow用户

发布于 2018-03-17 19:07:57

维护系统完整性的最佳方法是抑制服务总线消息的消耗。您可以控制QueueClient处理消息的方式,请参阅:https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dotnet-get-started-with-queues#4-receive-messages-from-the-queue

查看“最大并发调用”

代码语言:javascript
复制
 static void RegisterOnMessageHandlerAndReceiveMessages()
{
    // Configure the message handler options in terms of exception handling, number of concurrent messages to deliver, etc.
    var messageHandlerOptions = new MessageHandlerOptions(ExceptionReceivedHandler)
    {
        // Maximum number of concurrent calls to the callback ProcessMessagesAsync(), set to 1 for simplicity.
        // Set it according to how many messages the application wants to process in parallel.
        MaxConcurrentCalls = 1,

        // Indicates whether the message pump should automatically complete the messages after returning from user callback.
        // False below indicates the complete operation is handled by the user callback as in ProcessMessagesAsync().
        AutoComplete = false
    };

    // Register the function that processes messages.
    queueClient.RegisterMessageHandler(ProcessMessagesAsync, messageHandlerOptions);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49340233

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档