是否可以将队列名称设置到 appsettings.json 文件中?

Is it possible to set the queue name into an appsettings.json file?

为了动态启动进程,我使用了一个具有由 Azure 存储帐户队列触发的功能的 Web 作业。

我们有一个 "developpement" 和一个 "release" 版本的 Web 应用程序,因此我们希望针对存储帐户的不同队列来分隔我们的 Web 作业版本。我们目前通过在 appsettings.json 中使用 connectionStrings 来为我们的数据库做到这一点,我们想为我们的 webjobs 做同样的事情,但我们没有找到任何方法来做到这一点。

//What I have : 
public static async Task CFT([QueueTrigger("test")] string message, ILogger log)

//What I want to have (if possible):

public static async Task CFT([QueueTrigger(Configuration.GetString("TableStorage"))] string message, ILogger log)

如果这里不行,可以在主程序中做吗?

感谢您的帮助。

webjob支持自定义绑定表达式,可以参考文档:How to use the Azure WebJobs SDK for event-driven background processing。所以你需要做的就是像这样设置绑定%queuename%,并在appsettings.json中设置它,不需要设置任何其他东西。

这是我的测试。

appsettings.json

{
      "AzureWebJobsStorage": "connection sring",
      "queuename": "myqueue"
}

Function.cs

public static void ProcessQueueMessage([QueueTrigger("%queuename%")] string message, ILogger logger)
        {
            logger.LogInformation(message);
        }

结果: