‫Now let's talk
‫about Dead Letter Queues in SQS.
‫The idea is that let's get into the scenario
‫where a consumer fails to process a message
‫within the visibility timeout period.
‫Then we know that the message
‫automatically goes back into the queue.
‫So the consumer reads the message,
‫maybe there's a failure,
‫maybe we don't have enough time.
‫The message goes back into the queue.
‫Now, if that thing happens very often,
‫that can be a problem.
‫For example, we read again the message,
‫maybe there's something wrong with the message.
‫Maybe our consumer doesn't understand the message
‫or can't process the message.
‫Then the message will go back into the queue
‫and it will happen again.
‫We'll read the message again from SQS
‫and it will go again back into the queue.
‫So we can set a threshold
‫to how many times this can happen.
‫And,
‫this failure loop can be a big problem,
‫but we can set a MaximumReceives threshold.
‫And if that threshold is exceeded
‫then we can tell SQS to say,
‫"Well, this message looks a bit odd.
‫It looks like it's being processed too many times
‫and not successfully."
‫Therefore, send this into a Dead Letter Queue.
‫And the Dead Letter Queue will contain that message
‫and for later processing.
‫And so the message will be removed
‫from the first queue and sent into the second one.
‫Why do we have Dead Letter Queues?
‫Well Dead Letter Queues are very useful for debugging
‫and in case a message goes in Dead Letter Queue
‫because it is an SQS queue, you have to process it,
‫but at least it gives you time
‫to understand what is happening.
‫Few things to notice that the Dead Letter Queue
‫of a FIFO queue must also be a FIFO queue,
‫and the Dead Letter Queue of the Standard queue
‫must also be a Standard queue.
‫Finally, because we have a Dead Letter Queue, you need to
‫make sure that the messages are processed before
‫They expire
‫from the queue.
‫So it's a good idea to set a long time
‫for example, 14 days of retention
‫from
‫within the Dead Letter Queue.
‫And the next feature for management
‫of your Dead Letter Queues are the re drive to
‫source feature.
‫So it's a feature to help you consume messages in
‫the Dead Letter Queue to understand what is wrong with them.
‫So you have your messages
‫now you know they haven't been processed in the source queue
‫and therefore they are in the Dead Letter Queue
‫and you're going to do a manual inspection
‫and debugging of these messages.
‫And then you're going to fix your consumer code
‫understand why the message wasn't processed
‫in case the message was correct.
‫And then what you can do is re drive that message
‫from the dead letter queue into the source SQS queue
‫And what's going to happen with this is
‫that the consumer can now reprocess that message
‫without even knowing that the message went
‫into the Dead Letter Queue
‫and then the message processing has happened
‫and as a cool feature.
‫So now let us go into the console
‫so I can show you the Dead Letter Queue feature.