gpt4 book ai didi

amazon-web-services - Amazon Kinesis 和 AWS Lambda 重试

转载 作者:行者123 更新时间:2023-12-03 11:34:31 25 4
gpt4 key购买 nike

我对 很陌生亚马逊 Kinesis 所以也许这只是我理解中的一个问题,但在 AWS Lambda FAQ 中它说:

The Amazon Kinesis and DynamoDB Streams records sent to your AWS Lambda function are strictly serialized, per shard. This means that if you put two records in the same shard, Lambda guarantees that your Lambda function will be successfully invoked with the first record before it is invoked with the second record. If the invocation for one record times out, is throttled, or encounters any other error, Lambda will retry until it succeeds (or the record reaches its 24-hour expiration) before moving on to the next record. The ordering of records across different shards is not guaranteed, and processing of each shard happens in parallel.



我的问题是,如果由于某种原因,某些格式错误的数据被生产者放入分片,并且当 Lambda 函数将其取出时出错,然后不断重试,会发生什么?这意味着该特定分片的处理将被错误阻止 24 小时。

通过将问题包装在自定义错误中并将此错误与所有成功处理的记录一起发送到下游并让消费者处理它,是处理此类应用程序错误的最佳实践吗?当然,如果出现不可恢复的错误导致程序像空指针一样崩溃,这仍然无济于事:在接下来的 24 小时内,我们将再次回到阻塞重试循环。

最佳答案

不要想太多,Kinesis 只是一个队列。您必须成功消费一条记录(即从队列中弹出)才能继续下一条记录。就像一个先进先出堆栈。

适当的方法应该是:

  • 从流中获取记录。
  • 在 try-catch-finally 块中处理它。
  • 如果记录处理成功,没有问题。 <- 试试
  • 但是如果失败了,记下来到另一个地方调查
    失败的原因。 <- 捕捉
  • 在逻辑块的末尾,始终保持位置
    动态数据库。 <- 终于
  • 如果您的系统出现内部问题(内存错误、硬件错误
    等)那是另一个故事;因为它可能会影响处理所有
    记录,而不仅仅是一个。

  • 顺便说一句,如果处理记录的时间超过 1 分钟,很明显你做错了什么。由于 Kinesis 旨在每秒处理数千条记录,因此您不应奢侈地为每个记录处理如此长的作业。

    您问的问题是队列系统的一般问题,有时称为“有毒消息”。您必须在业务逻辑中处理它们以确保安全。

    http://www.cogin.com/articles/SurvivingPoisonMessages.php#PoisonMessages

    关于amazon-web-services - Amazon Kinesis 和 AWS Lambda 重试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32501985/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com