Reputation: 33
Azure WebJob obtains connection string from web application (which runs the job) configuration parameter - AzureWebJobsStorage. I need to monitor two queues in different storages using one WebJob. Is it possible somehow to have multiple connection strings for a WebJob?
Upvotes: 3
Views: 1288
Reputation: 29791
Related to this post it is possible :
In your case, you'd like to bind to differents storage accounts so your function can look like that:
public static void JobQueue1(
[QueueTrigger("queueName1"),
StorageAccount("storageAccount1ConnectionString")] string message)
{
}
public static void JobQueue2(
[QueueTrigger("queueName2"),
StorageAccount("storageAccount2ConnectionString")] string message)
{
}
You can also implement a custom INameResolver if you want to get the connectionstrings from the config :
public class ConfigNameResolver : INameResolver
{
public string Resolve(string name)
{
string resolvedName = ConfigurationManager.AppSettings[name];
if (string.IsNullOrWhiteSpace(resolvedName))
{
throw new InvalidOperationException("Cannot resolve " + name);
}
return resolvedName;
}
}
to use it:
var config = new JobHostConfiguration();
config.NameResolver = new ConfigNameResolver();
...
new JobHost(config).RunAndBlock();
And your new functions look like that:
public static void JobQueue1(
[QueueTrigger("queueName1"),
StorageAccount("%storageAccount2%")] string filename)
{
}
public static void JobQueue2(
[QueueTrigger("queueName2"),
StorageAccount("%storageAccount1%")] string filename)
{
}
appSettings
Upvotes: 3