Azure函数未使用队列绑定触发 [英] Azure function not triggering with queue binding

查看:86
本文介绍了Azure函数未使用队列绑定触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作正常的Azure WebJob,其队列绑定是这样的:

I have a working Azure WebJob with queue binding like this:

public static class Function1
{
    [FunctionName("Function1")]
    public static void Run([QueueTrigger("%input-queue%")]string myQueueItem, ILogger log)
    {
        log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
    }
}

我正在尝试将其转换为Azure函数.如果我将队列名称硬编码为 [QueueTrigger("input")] ,但我想使其可配置,则效果很好.如果将配置添加到我的 local.settings.json 文件中,则本地调试可以正常进行:

I'm trying to convert it to an Azure Function. It works fine if I hard-code the queue name like [QueueTrigger("input")] but I want to make it configurable. Debugging locally works fine if I add the configuration to my local.settings.json file:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "input-queue": "debug-input"
  },
}

问题是,我将"input-queue":"input" 添加到我的 appsettings.json 中,但是部署的函数不会触发.我在这里做错什么了吗?

The problem is, I add "input-queue": "input" to my appsettings.json but the deployed function won't trigger. Am I doing something wrong here?

我有以下 FunctionStartup :

using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using System.IO;

[assembly: FunctionsStartup(typeof(FunctionApp2.Startup))]

namespace FunctionApp2
{
    public class Startup : FunctionsStartup
    {
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            FunctionsHostBuilderContext context = builder.GetContext();

            builder.ConfigurationBuilder
                .AddJsonFile(Path.Combine(context.ApplicationRootPath, "appsettings.json"), optional: false, reloadOnChange: false)
                .AddJsonFile(Path.Combine(context.ApplicationRootPath, "local.settings.json"), optional: true, reloadOnChange: false)
                .AddEnvironmentVariables()
                .Build();
        }

        public override void Configure(IFunctionsHostBuilder builder)
        {
        }
    }
}

这是我的功能应用依赖项:

Here are my function app dependencies:

<ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.4" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.8" />
    <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.8" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.8" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.9" />
  </ItemGroup>

推荐答案

如注释中所述:

在Azure Functions中运行时,不会读取 appsettings.json 文件.在本地运行时读取 local.settings.json 是Functions核心工具调试经验的一部分.

The appsettings.json file is not being read in when running in Azure Functions. Reading the local.settings.json when running locally, is part of the debugging experience of the Functions core tools.

相反,在Azure中运行时,应使用功能的应用程序设置".这提供了其他功能,例如 Key Vault引用.

Instead, when running in Azure, you should use the App Settings of Functions. This provides additional features such as Key Vault references.

这篇关于Azure函数未使用队列绑定触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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