How to guarantee azure queue FIFO

前端 未结 6 781
予麋鹿
予麋鹿 2020-12-16 04:48

I understand that MS Azure Queue service document http://msdn.microsoft.com/en-us/library/windowsazure/dd179363.aspx says first out (FIFO) behavior is not guaranteed.

<
6条回答
  •  爱一瞬间的悲伤
    2020-12-16 05:30

    I don't know how fast do you want to process the messages, but if you need to have a real FIFO, don't allow Azure's queue to get more than one message at a time.

    Use this at your "program.cs" at the top of the function.

        static void Main()
                {
                    var config = new JobHostConfiguration();
    
                    if (config.IsDevelopment)
                    {
                        config.UseDevelopmentSettings();
                    }
                    config.Queues.BatchSize = 1; //Number of messages to dequeue at the same time.
                    config.Queues.MaxPollingInterval = TimeSpan.FromMilliseconds(100); //Pooling request to the queue.
    
    
                    JobHost host = new JobHost(config);
    
    ....your initial information...
    
                // The following code ensures that the WebJob will be running continuously
                host.RunAndBlock();
    

    This will get one message at a time with a wait period of 100 miliseconds.

    This is working perfectly with a logger webjob to write to files the traze information.

提交回复
热议问题