首页 > 解决方案 > 为什么我的 Azure 函数在消耗计划上运行时没有扩展?

问题描述

我有一个连接到服务总线队列的 Azure 函数。它接收消息并生成记录以保存在 Azure 表存储中。

Service Bus 队列当前有很多消息:

服务总线队列

由于有很多待处理的消息,我希望 Azure Functions 的扩展会发生,但似乎并非如此:

Azure 函数指标

只有一个函数实例正在运行,我希望有更多实例可以帮助清空队列。

正如Azure Function 的关于使用服务总线时进行缩放的文档中所指定的那样,我确保 Azure Function 使用的策略包括帮助缩放的管理权限:

服务总线队列策略

问题

为什么我的 Azure 函数在消耗计划上运行时无法扩展以帮助将所有消息从服务总线中取出?

更新

这是 Azure 函数的摘录:

public static class RecordImporter
{
    private static readonly IImporter Importer;

    static RecordImporter()
    {
        Importer = new AzureTableImporter();
    }

    [FunctionName("Importer")]
    public static async Task Run([ServiceBusTrigger("records ", Connection = "serviceBusConnectionString")] string serializedRecords, ILogger log)
    {
        var records = JsonConvert.DeserializeObject<List<Record>>(serializedRecords);
        await Importer.AddRecordsAsync(records);
    }
}

标签: c#azure.net-coreazure-functions

解决方案


只是一个想法,因为有些人面临服务总线触发器扩展的类似问题:

https://github.com/microsoft/azure-pipelines-tasks/issues/6759

我注意到您使用的是 C#,因此请在发布时执行此操作:

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

(清除从包文件中运行复选框。VS默认使用Zip部署,通过上述步骤可以更改为Web部署。)


推荐阅读