我有接收ServiceBusTrigger消息的函数:
resize
当我向" mysb"发送消息时Azure Que - 此功能开始工作。
我的问题是:我可以从App.config中获取Que名称吗?
答案 0 :(得分:2)
As a complement to sebbrochet's answer, you'll probably have to implement a custom INameResolver to get the value from the app.config file as this GitHub issue suggests.
https://github.com/Azure/azure-webjobs-sdk/issues/581
Just use %paramname% in the ServiceBus param when you want your custom resolver to kick in.
Hope that helps.
答案 1 :(得分:1)
这SO question似乎回答了你的问题。
您将使用此代码:Microsoft.WindowsAzure.CloudConfigurationManager.GetSettings("QueueName")
在app.config文件中使用这种代码:
<configuration>
<appSettings>
<add key="QueueName" value="mysb"/>
</appSettings>
</configuration>
答案 2 :(得分:0)
仅仅是@Baywet答案的实现,我是@dprothero发现的here。
在您的Program.cs
文件的Main
方法中,在注册Microsoft.Azure.WebJobs.JobHostConfiguration
时,为
INameResolver
的实现。
static void Main()
{
var config = new JobHostConfiguration
{
NameResolver = new QueueNameResolver()
};
//other configurations
}
和QueueNameResolver
类就像
public class QueueNameResolver : INameResolver
{
public string Resolve(string name)
{
return ConfigurationManager.AppSettings[name].ToString();
}
}
现在在<appSettings>
文件的App.config
部分中添加密钥,例如
<appSettings>
<add key="QueueName" value="myqueue" />
</appSettings>
并像
一样使用它 public async Task ProcessQueueMessage([ServiceBusTrigger("%QueueName%")] BrokeredMessage receivedMessage)