Most of the websites always require a batch processing job which can do resource intensive tasks like sending emails , listen to a queue etc. Azure Webjobs allows us to just that and its just a .NET console application which runs within the context of an azure website.
These jobs can be scheduled to run on demand, continuously, or on a predefined schedule with a recurrence.
Additionally, operations defined within WebJobs can be triggered to run either when the job runs or when a new file is created in Blob storage or a message is sent to an Azure queue.
To create a azure webjob with queue trigger
1.Go to Visual Studio -> Right click your website -> Add -> New Azure Webjob project
3.Modify the class Program so that it is public. If you do not make the class public, WebJobs will not detect and run your operations.
4.Inside Program.cs, add a using statement for Microsoft.Azure.WebJobs.
5.Inside main() you will see these 2 lines of code.
JobHost host = new JobHost();
which specifies that webjob will run continuously.
6.Next, add a method to be invoked by WebJobs, following method will invoked when a new message appears in the queue named myqueue.
public static void TriggerFunction([QueueTrigger(“myqueue”)]CloudQueueMessage message)
A webjob can also be triggered when a new blob is detected within the container.
To run this WebJob locally, you need to apply some local configuration. Open the App.config file and add connection strings for the canonical storage account connection strings expected by WebJobs SDK, AzureWebJobsDashboard, and AzureWebJobsStorage.
Be sure to replace name and key values with the values from your own storage account.
To test your webjob, set it as a startup project and press f5. Your webjob is up and running and waiting for a trigger, once a new message arrives in the queue the trigger function is trigerred.