简体   繁体   English

SQS批次中的所有消息是否在达到最大redrive(Retry)策略数后都发送到Dead Letter Queue

[英]Are all the messages in SQS batch sent to Dead Letter Queue after reaching the maximum redrive(Retry) policy number

I have a SQS queue and the consumer of this queue is a lambda and the unprocessed messages are being sent to a Dead Letter Queue with a redrive policy of 10.我有一个 SQS 队列,该队列的使用者是 lambda,未处理的消息被发送到重驱动策略为 10 的死信队列。

My SQS queue's batch size is 5, will all the messages in a particular batch be sent to the DLQ or only the ones which crossed the retry attempt of 10 and didn't process would go to DLQ.我的 SQS 队列的批处理大小为 5,将特定批处理中的所有消息发送到 DLQ,还是仅将超过 10 次重试尝试且未处理的消息发送到 DLQ。

If 3 messages in a batch of 5 got successfully processed, will all 5 go to DLQ or only the 2 that didn't get processed.如果 5 条消息中的 3 条消息成功处理,则将所有 5 条 go 到 DLQ 或只有 2 条未处理。

The process of sending msgs to DQL is independent of lambda function or its batch setup.将消息发送到 DQL 的过程独立于 lambda function 或其批处理设置。 SQS evaluates whether a msg should be send to DLQ on per-message basis. SQS 评估是否应根据每条消息将消息发送到 DLQ。 It does not depend on your lambda function or how large batches lambda is using.它不取决于您的 lambda function 或 lambda 正在使用的大批量。

So only 2 would be send to DLQ, not entire batch.所以只有 2 个会被发送到 DLQ,而不是整个批次。

The answer is highly dependent and absolutely coupled to what your lambda is actually doing.答案高度依赖并且绝对与您的 lambda 实际执行的操作相关。

How would SQS know whether a message was "successfully processed" or not? SQS 如何知道消息是否“成功处理”? Your lambda is iterating over a batch of messages and as long as no error is raised in the handler, the entire batch is considered successful and those messages are acknowledged and removed from the source SQS queue.您的 lambda 正在迭代一批消息,只要处理程序中没有引发错误,整个批次就被认为是成功的,并且这些消息被确认并从源 SQS 队列中删除。 On the other hand if any error is raised during the iteration through the batch the entire batch is considered a complete failure and all messages would return to the queue.另一方面,如果在批次的迭代过程中出现任何错误,则整个批次都被视为完全失败,所有消息都将返回到队列中。

Post Nov 23, 2021, https://aws.amazon.com/about-aws/whats-new/2021/11/aws-lambda-partial-batch-response-sqs-event-source/ AWS now supports a partial batch response. 2021 年 11 月 23 日发布, https://aws.amazon.com/about-aws/whats-new/2021/11/aws-lambda-partial-batch-response-sqs-event-source/ AWS 现在支持部分批处理回复。

Until now, a batch being processed through SQS polling would either be completely successful, in which case the records would be deleted from the SQS queue, or would completely fail, and the records would be kept on the queue to be reprocessed after a 'visibility timeout' period.到目前为止,通过 SQS 轮询处理的批次要么完全成功,在这种情况下,记录将从 SQS 队列中删除,要么完全失败,记录将保留在队列中以在“可见性”后重新处理超时”期间。 The Partial Batch Response feature an SQS queue will only retain those records which could not be successfully processed, improving processing performance. SQS 队列的 Partial Batch Response 功能只会保留那些无法成功处理的记录,从而提高处理性能。

https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting

To avoid reprocessing all messages in a failed batch, you can configure your event source mapping to make only the failed messages visible again.为避免重新处理失败批次中的所有消息,您可以配置事件源映射以仅使失败的消息再次可见。 To do this, when configuring your event source mapping, include the value ReportBatchItemFailures in the FunctionResponseTypes list.为此,在配置事件源映射时,请将值 ReportBatchItemFailures 包含在 FunctionResponseTypes 列表中。 This lets your function return a partial success, which can help reduce the number of unnecessary retries on records.这让您的 function 返回部分成功,这有助于减少对记录的不必要重试次数。

Report syntax After you include ReportBatchItemFailures in your event source mapping configuration, you can return a list of the failed message IDs in your function response.报告语法 在事件源映射配置中包含 ReportBatchItemFailures 后,您可以在 function 响应中返回失败消息 ID 的列表。 For example, suppose you have a batch of five messages, with message IDs id1, id2, id3, id4, and id5.例如,假设您有一批 5 条消息,消息 ID 为 id1、id2、id3、id4 和 id5。 Your function successfully processes id1, id3, and id5.您的 function 成功处理了 id1、id3 和 id5。 To make messages id2 and id4 visible again in your queue, your response syntax should look like the following:要使消息 id2 和 id4 在您的队列中再次可见,您的响应语法应如下所示:

{ "batchItemFailures": [ { "itemIdentifier": "id2" }, { "itemIdentifier": "id4" } ] } {“batchItemFailures”:[{“itemIdentifier”:“id2”},{“itemIdentifier”:“id4”}]}

TLDR; TLDR;

The default behavior of any exceptions that happen in a lambda is to return the entire batch of messages back to the source. lambda 中发生的任何异常的默认行为是将整批消息返回给源。 In order to remove only the successfully processed messages and return unsuccessful messages back to the queue, your function must try/catch around each message, save the ids of the unsuccessful messages and return that payload.为了只删除成功处理的消息并将不成功的消息返回到队列,您的 function 必须尝试/捕获每条消息,保存不成功消息的 id 并返回该有效负载。 That will cause the receive count to increment on the unsuccessful messages and then depending on your DLQ policy, once an individual message's receive count is reached that message is diverted to the DLQ.这将导致接收计数在不成功的消息上增加,然后根据您的 DLQ 策略,一旦达到单个消息的接收计数,该消息将被转移到 DLQ。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM