skip to Main Content

so far I am need to get Azure Queue messages and it releated to each others, for example:

[{
id: 1,
message: "this message should be executed first",
timestamp: "2023-10-30"
},
{
id: 2,
message: "this message should be executed later",
timestamp: "2023-10-29"
}]

imaging after getting messages for Azure Queue messages and I got an array of message object, and message with id 1 should executed first and next is message with id 2. In case the process executing id 1 fails and then the process of message with id 2 will not be executed

I want all the message will be executed in order of FIFO and make sure the previous process that it was relied on executed successfully then it will be executed

Plus, there is a case for hundered of messages relied on each other in the real world situation, what should I implemented, for example:

message with id 3 relied on id 2 and id 1 completed;
message with id 4 relied on id 3, id 2 and id 1 completed;

message with id n relied on id n-1, id n-2 and id n-3 … id 1 completed;

thank u so much for guiding me to handle this challenge, really appreciate that even though you guys just taking time to look at my problem

P/s: not allow using multiple queue

2

Answers


  1. A queue cannot handle this scenario for you automatically as it does not understand the relationship between your different queue items.

    You need to handle it with your own logic. For example, you can check in your database if you are ready for id 2 yet and if not, you can put the item back in the queue but with a delay.

    queue.AddMessage(message, initialVisibilityDelay: TimeSpan.FromHours(1));
    

    But the whole idea is dangerous because if a queue item fails to be processed, what makes you think it will succeed the next time? And if it doesn’t succeed, then more and more faulty queue items will gradually clog up the system.

    Login or Signup to reply.
  2. You may want to check out Azure Service Bus, which allows you to implement FIFO pattern using sessions https://learn.microsoft.com/en-us/azure/service-bus-messaging/message-sessions#first-in-first-out-fifo-pattern

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search