5

I have two differents scenarios to process 2 different types of queues using Azure queue storage.

I want to set a queue to run one after another, and the other to run simultaneously.

I've been looking at the documentation and I can apply the configuration to the host affecting the whole range of queues.

static void Main(string[] args)
    {
        JobHostConfiguration config = new JobHostConfiguration();
        config.Queues.BatchSize = 8;
        config.Queues.MaxDequeueCount = 4;
        config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(15);
        JobHost host = new JobHost(config);
        host.RunAndBlock();
    }

so can I configure those scenarios by using a single azure storage account?

pedrommuller
  • 15,741
  • 10
  • 76
  • 126

1 Answers1

1

From your question, I understand you have 2 queues and each queue needs to be used to process different tasks/jobs.

You can follow these approaches

1) Deploy 2 Web jobs, each wait on different queues and trigger corresponding job whenever a message appears on respective queue. The config code you mentioned above sets the base for one job. And AFAIK, a job can wait on one queue. You can have a method like this next to Main() method

public static void ProcessQueueMessage([QueueTrigger("logqueue")] string logMessage)
{
    //do something
}

2) if you want to trigger multiple scenarios based on messages from one queue, you can have an if else block on the ProcessQueueMessage method or if you want to make it more manageable, use Strategy pattern to execute right method from ProcessQueueMessage

If you follow #1 above, you will deploy different web jobs for each task/job/scenario. If you follow #2 above, you will deploy one web job and what each message does is decided while processing the message.

Documentation related to waiting on queue here.

[Update]

As we know one web job can wait on only one queue, waiting on the queue is not the right approach in this case. Better trigger the web job periodically (say once in 5 mins). Logic to dequeue messages from multiple queues and processing them will be part of one web job. Processing each queue can be a method which gets called by the web same job (one after another or concurrently using Task). You can pass message count on the CloudQueue.GetMessages for each queue. It will be very similar to what the windows service does. Just that the triggering part is taken care by the web job and it runs as a web job rather than windows service. Here is a rough pseudocode:

main()
{
  // initialize webjob
}
public static MyWebJobMethod(...)
{
    Task a = () => {//process queue 1};
    Task b = () => {//process queue 2}
    Task.WaitAll(a,b);
}
Amit
  • 25,106
  • 25
  • 75
  • 116
  • thanks for your answer I've looked at that documentation prior to post the question, I don't have te option to deploy more web jobs, actually I'm running a windows service that's doing the web job role perfectly fine, the issue is how can I set "The maximum number of queue messages that are picked up simultaneously", per queue let's say one trigger should fire one at the time and other could have the default configuration. – pedrommuller Mar 11 '15 at 15:43
  • http://azure.microsoft.com/en-us/documentation/articles/websites-dotnet-webjobs-sdk-storage-queues-how-to/#config – pedrommuller Mar 11 '15 at 15:44
  • I didn't but I'll mark it as answer for the effort. – pedrommuller Mar 15 '15 at 00:58