Singleton Azure函数作为单独的实例运行 [英] Singleton Azure function running as separate instances

查看:63
本文介绍了Singleton 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.

我们需要将函数用作单例,以便我们一次可以处理一个请求而不会发生任何冲突.根据我们在本文中的研究(

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 设置为 1 .us/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
            }
        }
    }
}

这篇关于Singleton Azure函数作为单独的实例运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆