Introduction
In this article, we will learn about how to create a Web Job using .Net Core with Service bus triggered.
Prerequisite
- Microsoft Azure account.
- .Net Core 3.1
- Visual Studio 2019 will be preferable.
What is Web Job
Web Job is something like a scheduler. We can set functionality to run in a specific interval of time or we can trigger a Web job when a new message came in Message Queue. We can trigger a web job in three different ways. Web Jobs can be triggered on Queue, Service Bus, Blob, etc. Here I giving some detail to create ServiceBus Trigger.
We can split code based on the following,
- Web job creation
- Sending a message to Queue to trigger Web job
- Debugging and check
Web Job creation
Step 1
Create Azure ServiceBus namespace from Azure Portal (www.Portal.azure.com).



After creating Service Bus Namespace,
Step 2
Create a .Net Core - C# Console application. The framework you can select is .Net Core 3.1.
Step 3
Add "Javascript JSON Configuration File". Specify the file name as "appsettings.json". Right-click and select the Properties of "appsettings.json" and Select "Copy To Output Directory" = "Copy If Never".
For taking ServiceBus ConnectionString, Navigate to Service Bus > Shared access policies > RootManageSharedAccessKey > Primary Connection String > click on the copy button on the right side of the text box.

{
"AzureWebJobsServiceBus": "<Place Your Service Bus Primary Connection String Here>"
}
Step 4
Open Program.cs and add the following namespace.
using Microsoft.Extensions.Hosting;
using System.Threading.Tasks;
You can use the following command to install the package on NuGet Package Manager Console ( First package is for -> HostBuilder() | 2nd is for -> AddServiceBus() ).
PM> Install-Package Microsoft.Azure.WebJobs.Extensions -version 4.0.1
PM> Install-Package Microsoft.Azure.WebJobs.Extensions.ServiceBus -IncludePrerelease
Add the following code for creating a Host,
class Program {
static async Task Main() {
var hostBuilder = new HostBuilder();
hostBuilder.ConfigureWebJobs((context, builder) => {
builder.AddServiceBus(options => options.MaxConcurrentCalls = 1);
});
var host = hostBuilder.Build();
using(host) {
await host.RunAsync();
}
}
}
Step 5
Add a Class file named Functions.cs. Add the following namespaces.
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;
Install the package using the following commands. The following command is for installing Logging methods. Microsoft.Azure.WebJobs, is already a part of the previously installed package.
PM> Install-Package Microsoft.Extensions.Logging.Console -version 5.0.0
Use the following code for triggering a function, when any message is in the service bus message queue.
public class Functions {
public static void processservicebus([ServiceBusTrigger("webjob1", Connection = "AzureWebJobsServiceBus")] string myQueueItem, ILogger log) {
log.LogInformation(myQueueItem);
}
}
You have to remember the Queue name (Queue name you can use any string), whatever you are giving here same needs to give in the Client-side method also.
Sending a message to Queue to trigger Web job
Now we can go ahead and create code to send messages.
Step 1
Create another Net Core - C# Console application. The framework you can select is .Net Core 3.1.
Step 2
Open Program.cs and add the following namespace.
using System.Threading.Tasks;
using Azure.Messaging.ServiceBus;
using System.Text.Json;
And use the following code to send messages.















Join the conversation! Your thoughts help the community grow.