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?
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With