How to guarantee azure queue FIFO

前端 未结 6 780
予麋鹿
予麋鹿 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:17

    Adding to @RichBower answer... check out this... Azure Storage Queues vs. Azure Service Bus Queues

    MSDN (link retired) http://msdn.microsoft.com/en-us/library/windowsazure/hh767287.aspx

    docs.microsoft.com https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-azure-and-service-bus-queues-compared-contrasted

    0 讨论(0)
  • 2020-12-16 05:20

    The docs say for Azure Storage queues that:

    Messages in Storage queues are typically first-in-first-out, but sometimes they can be out of order; for example, when a message's visibility timeout duration expires (for example, as a result of a client application crashing during processing). When the visibility timeout expires, the message becomes visible again on the queue for another worker to dequeue it. At that point, the newly visible message might be placed in the queue (to be dequeued again) after a message that was originally enqueued after it.

    Maybe that is good enough for you? Else use Service bus.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-16 05:32

    As mentioned here https://www.jayway.com/2013/12/20/message-ordering-on-windows-azure-service-bus-queues/ ordering is not guaranteed also in service bus, except of using recieve and delete mode which is risky

    0 讨论(0)
  • 2020-12-16 05:33

    The latest Service Bus release offers reliable messaging queuing: Queues, topics and subscriptions

    0 讨论(0)
  • 2020-12-16 05:33

    You just need to follow below steps to ensure Message ordering.:

    1) Create a Queue with session enabled=false. 2) While saving message in the queue, provide the session id like below:-

    var message = new BrokeredMessage(item);
    message.SessionId = "LB";
    Console.WriteLine("Response from Central Scoring System : " + item);
    client.Send(message);
    

    3) While creating receiver for reviving message:-

    queueClient.OnMessage(s =>
    {
        var body = s.GetBody<string>();
        var messageId = s.MessageId;
        Console.WriteLine("Message Body:" + body);
        Console.WriteLine("Message Id:" + messageId);
    });
    

    4) While having the same session id, it would automatically ensure order and give the ordered message.

    Thanks!!

    0 讨论(0)
提交回复
热议问题