Singleton Azure function running as separate instances(单例 Azure 函数作为单独的实例运行)
问题描述
我们有一个 Azure 函数,它应该同时处理多个服务总线触发器,我假设正在发生的事情是它被拆分到多个实例中,这导致了我们端的一些并发问题.
We have an Azure function that is supposed to be handling several service bus triggers at the same time and what I assume is happening is that it is being split across several instances which is causing some concurrency problems on our end.
我们需要我们的函数充当单例,这样我们就可以一次处理一个请求而不会发生任何冲突.根据我们在本文中的研究 (https://docs.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#singleton-attribute) 我们应该能够做到这一点.
We need our function to act as a singleton so we can process requests one at a time without any collisions. From what we looked into in this article (https://docs.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#singleton-attribute) we should be able to accomplish this.
我们的函数如下所示:
[Microsoft.Azure.WebJobs.Singleton(Mode = SingletonMode.Listener)]
[FunctionName("AccountCreatedSubscriber")]
public static void Run([ServiceBusTrigger("accountscontacts-account-created", "license-keys", Connection = "FBISEventBus")]BrokeredMessage message, ILogger log)
{
log.LogInformation($"{{ Message received from accountscontacts-account-created topic }}");
// Do Work
log.LogInformation($"{{ Message sent to account creation handler }}");
}
为了备份,我们的 host.json 文件中也有这个,
And for backup we also have this in our host.json file,
{
"serviceBus": { "maxConcurrentCalls": 1 }
}
但无论出于何种原因,我们的函数仍在并行运行.有什么想法吗?
But for whatever reason our functions are still running parallel. Any ideas?
推荐答案
如果您的函数在消耗计划中,请在 WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT 设置为
1
us/azure/azure-functions/functions-app-settings#websitemaxdynamicapplicationscaleout" rel="noreferrer">应用程序设置.
If your function is on Consumption plan, set
WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT
to1
in Application settings.
在门户中检查您的 Azure Function 运行时版本(平台功能> 函数应用设置).如果是~2,我们需要在 host.json 如下.
Check your Azure Function runtime version in portal(Platform features> Function app settings). If it's ~2, we need to modify service bus setting in host.json as below.
{
"version": "2.0",
"extensions": {
"serviceBus": {
"messageHandlerOptions": {
"maxConcurrentCalls": 1
}
}
}
}
这篇关于单例 Azure 函数作为单独的实例运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:单例 Azure 函数作为单独的实例运行


- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01