0
votes

I have an Azure webjob that is triggered by a queue (inherited, not originally written by me). The queue usually only has one item placed on it at a time, but on the first of every month has many items.

On these occasions it has always processed one queue item at a time, finishing processing before picking up the next.

I noticed, however, that as of a couple of months ago it started processing two files at any one time, which is causing problems.

Whilst i could refactor the code to allow for this, I really don't have the time, and the return would be minimal. I simply want it to process one item at a time again, but i cant find anything that may have caused this to change. Are there any settings in the azure portal I should be aware of? I don't believe any code relating to the trigger itself has changed.

Thank you in advance

2

2 Answers

0
votes

Sure, this can be done. Note that a WebJob can be triggered by either a Service Bus Queue or an Azure Storage Queue. Here's info for both.

For Azure Storage Queues

By default, a QueueTrigger will grab 16 messages at a time and process them in parallel. If you don't want this, you need to set the JobHostConfiguration instance's BatchSize property to 1 in your WebJob's static void Main method. Example:

 static void Main(string[] args)
 {
     JobHostConfiguration config = new JobHostConfiguration();
     config.Queues.BatchSize = 8;
     JobHost host = new JobHost(config);
     host.RunAndBlock();
 }

For Service Bus Queues

Similarly, you'll set properties in the JobHostConfiguration. If you're using Service Bus, there's a little more setup. Example:

static void Main(string[] args)
{    
    JobHostConfiguration config = new JobHostConfiguration();
    ServiceBusConfiguration serviceBusConfig = new ServiceBusConfiguration();
    serviceBusConfig.MessageOptions.MaxConcurrentCalls = 1;
    config.UseServiceBus(serviceBusConfig);

    JobHost host = new JobHost(config);
    host.RunAndBlock();
}
0
votes

In my case, the problem was that someone had scaled out the Azure app service to 2 instances. However, I'm marking Rob's answer as the most helpful.