Search code examples
c#azureazureservicebusazure-webjobs

Azure triggered webjob not triggering when there are message in azure service bus


I have a web job that is supposed to be a triggered web job. I have it been deployed to azure fine and it is listed as a triggered webjob. However when I add things to the azure service bus that it has a function for. When i trigger it from the UI it works and will respond to my messages.

My host is configured like so

var config = new JobHostConfiguration
        {
            JobActivator = new MyActivator(container)
        };
        config.UseServiceBus();
        var host = new JobHost(config);
        host.RunAndBlock();

My Function looks something like this

public  void ProcessQueueMessage([ServiceBusTrigger("recipetest")] ProductName message, TextWriter log)
    {
        //code
    }

I have been looking for a while now but all google searches have given me back continuous web jobs with function triggers. Can anyone tell me how to get the web job to wake up and handle messages. I have found most other answers talk about always on but triggered jobs should work without always on.


Solution

  • To use ServiceBusTrigger, your WebJob has to be continuous.

    To add a little more detail, the ServiceBusTriggerAttribute actually does poll the Message Queue that it monitors using a backoff if no messages are found. So you can see that messages added to the queue do not "wake up" a WebJob and tell it to do something - instead the ServiceBusTriggerAttribute polls and will find when new messages are waiting to be processed. This is why the WebJob can't be Triggered if you're using ServiceBusTriggerAttribute.