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 设置为
1us/azure/azure-functions/functions-app-settings#websitemaxdynamicapplicationscaleout" rel="noreferrer">应用程序设置.
If your function is on Consumption plan, set
WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUTto1in 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 函数作为单独的实例运行
基础教程推荐
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
