单例 Azure 函数作为单独的实例运行

Singleton Azure function running as separate instances(单例 Azure 函数作为单独的实例运行)
本文介绍了单例 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?

推荐答案

  1. 如果您的函数在消耗计划中,请在 WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT 设置为 1us/azure/azure-functions/functions-app-settings#websitemaxdynamicapplicationscaleout" rel="noreferrer">应用程序设置.

  1. If your function is on Consumption plan, set WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT to 1 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 函数作为单独的实例运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)