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 !