DEV Community

Discussion on: Ordered queue processing in Azure Functions with Sessions

Collapse
 
jeffhollan profile image
Jeff Hollan

It will retry the message according to whatever retry policies you've set on the queue. So there's definitely a world you could see:

>lrange Patient-$10 0 -1
1) "Message-0"
2) "Message-0"
3) "Message-1"
4) "Message-2"
5) "Message-3"

Eventually I expect the message would "deadletter" and processing on the session would continue. Here's the key line in the sessions doc:

A new message can only be obtained [for that session] when the prior message has been completed or dead-lettered. Abandoning a message causes the same message to be served again with the next receive operation.

Collapse
 
thetinomen profile image
Bob Langley

If that is the case, to ensure proper business logic as described in this scenario, I would not rely on message ordering.

Using only Azure Functions it would make more sense to me to use Durable Function(s) to orchestrate the business logic, probably using the external events and/or monitoring patterns.

Thread Thread
 
jeffhollan profile image
Jeff Hollan

Even with durable you’re going to have at-least-once guarantees. You have more control over some of the retries for sure, but a scenario of “message 1 is poisoned. It won’t ever successfully process” is going to be a scenario your app will need to come to terms with regardless if functions or not. Do you not ever process 2-4? If you tried to resubmit message 1 it would go to back of queue anyway, so how does your app get to it? You’re not wrong that durable may provide a bit more control here but some of the problems if you want your app to be “once and always once” successful delivery just aren’t very feasible in a distributed cloud world.

Collapse
 
devakumar profile image
Devakumar

We have done custom logic to handle this. We moved the message to a SQL table after the retries. If a new message arrives with same session available in SQL table, then the message will be moved to SQL table without processing. There was separate timer function to notify / process / cleanup the data in SQL table.