1
votes

I'm trying to find out if it is possible to run a manually scheduled webjob, and have it started when a message arrives on a servicebus queue.

So the webjob would not run continuously, but only when a message arrives. (thus saving resource costs)

What I tried so far:

In Program.cs

public static async Task Main()
    {
        JobHostConfiguration config = new JobHostConfiguration();

        _servicesBusConnectionString = AmbientConnectionStringProvider.Instance.GetConnectionString(ConnectionStringNames.ServiceBus);

        ServiceBusConfiguration serviceBusConfig = new ServiceBusConfiguration();

        config.UseServiceBus(serviceBusConfig);

        JobHost host = new JobHost(config);

        Console.WriteLine("Starting host");
        host.RunAndBlock();
    }

In Functions.cs

public static void SBQueue2SBQueue([ServiceBusTrigger("createinvoice")] string start)
{
    Console.WriteLine("Receiving a message");
}

And a run.cmd to start the process

@echo off

dotnet CoreConsoleWebJob.dll

However, in this solution, I start the manually trigered webjob from the azure console. The host.RunAndBlock(); blocks the thread, but after some time the process fails because it has been idle too long and the webjob is shut down.

Is there a possibility that the process is invoked by the azure servicebus infrastructure ? Or is a continuous webjob always the way to go.

Thanks in advance !

1

1 Answers

2
votes

A webjob runs on an App Service Plan. And since you're already paying for the App Service Plan, you're not saving any money not having the webjob run continuously. If you're looking into saving money, have a look at runnning this as an Azure Function on a Consumption Plan.

That does save money, since you only pay when the function runs. And the triggers work out of the box, which is nice :)

When you're using a Consumption plan, instances of the Azure Functions host are dynamically added and removed based on the number of incoming events. This serverless plan scales automatically, and you're charged for compute resources only when your functions are running.

More info here: Azure Service Bus bindings for Azure Functions