Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Azure WebJob queue name at runtime?

I am developing an Azure WebJobs executable that I would like to use with multiple Azure websites. Each web site would need its own Azure Storage queue.

The problem I see is that the ProcessQueueMessage requires the queue name to be defined statically as an attribute of the first parameter inputText. I would rather have the queue name be a configuration property of the running Azure Website instance, and have the job executable read that at runtime when it starts up.

Is there any way to do this?

like image 692
eklein23 Avatar asked Mar 28 '14 19:03

eklein23


People also ask

How do I change my Azure WebJob schedule?

To change the schedule, or to Modify the CRON value just use the App Service Editor to modify the WWWROOT/App_Data/jobs/triggered/YOUR_WEBJOB_NAME/settings. job file; By the time of writing, App Service Editor is still in preview but it will work.

What is difference between WebJob and Azure function?

Webjobs run as background processes in the context of an App Service web app, API app, or mobile app whereas Functions run using a Classic/Dynamic App Service Plan.

How do I run a WebJob in Visual Studio?

In Visual Studio, select File > New > Project. Under Create a new project, select Console Application (C#), and then select Next. Under Configure your new project, name the project WebJobsSDKSample, and then select Next. Choose your Target framework and select Create.


1 Answers

This can now be done. Simply create an INameResolver to allow you to resolve any string surrounded in % (percent) signs. For example, if this is your function with a queue name specified:

public static void WriteLog([QueueTrigger("%logqueue%")] string logMessage) {     Console.WriteLine(logMessage); } 

Notice how there are % (percent) signs around the string logqueue. This means the job system will try to resolve the name using an INameResolver which you can create and then register with your job.

Here is an example of a resolver that will just take the string specified in the percent signs and look it up in your AppSettings in the config file:

public class QueueNameResolver : INameResolver {     public string Resolve(string name)     {         return ConfigurationManager.AppSettings[name].ToString();     } } 

And then in your Program.cs file, you just need to wire this up:

var host = new JobHost(new JobHostConfiguration {   NameResolver = new QueueNameResolver() }); host.RunAndBlock(); 
like image 83
dprothero Avatar answered Sep 22 '22 11:09

dprothero