Join Tiago Costa for an in-depth discussion in this video Create a WebJob, part of Developing Long-Running Tasks with Microsoft Azure.
- [Instructor] Now it's time to create an Azure WebJob, but before we need to check of the prereqs. So in order to be able to run an Azure WebJob, we need to have an Azure App Service plan. This is the compute capacity where our Azure WebJob will be running, and of course I also need an Azure web app, that can be also an API app, or even a mobile app, where my Azure WebJob will be deployed. So how do I create an Azure WebJob? So I have several options. First option, I can just create an executable file, like a console app. That console app could be just a .NET app, or a .NET core app, or even other languages like Java, Node, whatever, and then I can just upload this file through the Azure portal, or through Azure PowerShell or even through the Azure CLI. I can also take a more professional approach to this and I can just use the Azure WebJob template on Visual Studio. So I will create a new project in Visual Studio and then I will deploy it and deploy it I can deploy this using Visual Studio directly, or I can also use a more professional way on deploying this Azure DevOps. So now let's take a look on how to create an Azure WebJob using Visual Studio. Okay so now let's create an Azure WebJob using Visual Studio. So for this I'm just going to click create a new project, and under cloud I have a template that says Azure WebJob, and this will provide me a already made WebJob. So let's give your a name, like for example, lilDemoWebJob, let's press okay. So we're creating our project, so there you go. We have our project here created, so we have a main method here, that has all the configurations and then I have the host, and then I have the run and block. This run and block here ensures that the WebJob is always running, so it's running continuously. So for this to work I need to go to solution explorer, I need to go to my app configuration form, and I need a connection string from an Azure Storage account, so that I can have the Azure WebJob dashboard part and the job storages. Let's go for the Azure portal. So under the Azure portal, I already set it up an Azure Storage account so I just my access keys. I'll just go for the access keys and I will just copy my connection string, and now I can just paste the connection string, okay, in both of them, and in my case and for demo purposes I'm just using the same connection string for both of them. Now that this is running, so I can just show you also here the functions part. This is my Azure WebJob functions, and I have a function here that says the ProcessQueueMessage, that has an annotation for a queue trigger, so this is my trigger. So what I need to have is an Azure Storage queue, that it's named queue. This is already precreated also on our Azure Storage account. I will just fire up my WebJob. So it's running and as you can see, okay, a new queue message was detected on the queue, because let's go back to the portal, go under the portal and if I go to queues, I already have a queue called queue, and I already had a message here, cause I already did add a message and I'll just put test one, two, three, and I'll hit okay. If I now go back to my program, so this caught the message because I already had a message there.
- Creating and using Azure Storage queues
- Using Azure Service Bus queues
- Security for Azure Service Bus queues
- Creating and scheduling WebJobs
- Creating Azure functions
- Running Azure Batch workloads