SQS Lambda-重试逻辑? [英] SQS Lambda - retry logic?

查看:246
本文介绍了SQS Lambda-重试逻辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将消息添加到SQS队列中并将其配置为触发lambda函数(nodejs)时.

When the message has been added to an SQS queue and it is configured to trigger a lambda function (nodejs).

当触发lambda函数时-我可能想在5分钟后重试相同的消息,而不从队列中删除该消息.如果Lambda无法连接外部主机(例如:API),我想这样做的原因-我想在5分钟后仅尝试3次再试一次.

When a lambda function is triggered - I may want to retry same message again after 5 minute without deleting the message from the Queue. The reason I want to do this if Lambda could not connect external host (eg: API) - i like to try again after 5 minutes for 3 attempts only.

如何用node js编写?

How can that be written in node js?

例如在Laravel中,我们可以使用Specifying Max Job Attempts功能.使用public $tries = 5;

For example in Laravel, we can Specifying Max Job Attempts functionality. The number of times the job may be attempted using public $tries = 5;

来源: https://laravel.com/docs/5.7/queues#max-job-尝试和超时

我们如何在node.js中做类似的事情?

How can we do similar fashion in node.js?

我正在考虑将消息添加到另一个队列(以重试). Lambda函数会在5分钟后读取该队列中的所有消息,然后将该消息发送回主队列,这将触发Lambda函数.

I am thinking adding a message to another queue (for retry). A lambda function read all the messages from that queue after 5 minutes and send that message back to main Queue and it will be trigger a lambda function.

推荐答案

这是我的操作方式.

  1. 第1季度创建普通队列(立即交付)
  2. 第二季度创建延迟队列(延迟5分钟)
  3. 创建DLQ(重试后),DLQ1

(Q1/Q2)SQS触发器-> Lambda L1(如果失败,请在(Q1/Q2)上删除,并放下 它在第二季度)->在失败DLQ上

(Q1/Q2) SQS Trigger --> Lambda L1 (if failed, delete on (Q1/Q2), drop it on Q2) --> On Failure DLQ

当消息到达Q1时,如果从那里成功,它将触发Lambda L1.如果失败,则将其放到Q2(这是一个延迟的队列).第二季度到达的每条消息都会有5分钟的延迟.

When messages arrive on Q1 it triggers Lambda L1 if success goes from there. If fails, drop it to Q2 (which is a delayed queue). Every message that arrives on Q2 will have a delay of 5 minutes.

如果您的初始消息可能会延迟5分钟,那么您可能不需要两个队列.一个队列应该很好.如果初始延迟不可接受,则需要两个队列.拥有两个队列的另一个原因是,您将始终有一种方法来获取路径中出现的新消息.

If your initial message can have a delay of 5 mins, then you might not need two queues. One queue should be good. If the initial delay is not acceptable then you need two queues. One another reason to have two queues, you will always have a way for new messages that comes in the path.

如果您在处理Q1/Q2时遇到代码故障,则AWS基础结构将立即重试3次,然后再将其发送到DLQ1.如果您处理了代码中的错误,则可以使管道与您提到的时间配合使用.

If you have a code failure in handling Q1/Q2 aws infrastructure will retry immediately for 3 times before it sends it to DLQ1. If you handle the error in the code, then you can get the pipeline to work with the timings you mentioned.

SQS延迟队列:

https://docs.aws.amazon. com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-delay-queues.html

SQS Lambda体系结构:

https://nordcloud.com/amazon-sqs-as -a-lambda-event-source/

希望对您有所帮助.

Hope it helps.

这篇关于SQS Lambda-重试逻辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆