Take this conceptually simple task: consuming a queue, sending an email for each entry.
A simple approach would be:
while true:
entry = queue.pop()
sendMail();
The problem here is, if the consumer crashes after popping but before/during sending the mail, a mail is lost. So you change it to:
while true:
entry = queue.peek()
sendMail();
queue.pop();
But now, if the consumer crashes after mailing, but before popping, the mail will be sent again when the consumer comes back up.
What's the best-practice way of handling this problem?
Preferably, assume that the popping of the queue is the only record of the mail having been sent, so the mail subsystem does not record anything itself.
Aucun commentaire:
Enregistrer un commentaire