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

时间:2019-07-26 16:17:51

标签: .net-core triggers azure-webjobs

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

我们有Web应用程序的“开发版”和“发行版”,因此我们希望将存储帐户的不同队列作为目标,以分隔Webjobs的版本。当前,我们通过在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)

如果在这里不可能,例如可以在Main程序中做到吗?

谢谢您的帮助。

1 个答案:

答案 0 :(得分:0)

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);
        }

结果:

enter image description here