简体   繁体   English

在背压的情况下,AWS SQS 块出队

[英]AWS SQS block dequeue in case of back pressure

In case of lambda workers processing batches from an SQS queue, Is there an option to monitor the worker's failure rate (wrt processing job) and block further dequeueing (and as a result, lambda invocations) in case failure rate crosses a threshold?如果 lambda 工作人员处理来自 SQS 队列的批处理,是否有选项可以监控工作人员的失败率(wrt 处理作业)并阻止进一步出队(以及因此,lambda 调用)以防失败率超过阈值? I can monitor lambda's error/invocation rate, but how would the dequeue halting be implemented?我可以监控 lambda 的错误/调用率,但是如何实现出队停止? I don't want to empty the queue and lose the data.我不想清空队列并丢失数据。

First thing is to understand why your Lambda could (possibly) be failing:首先要了解为什么您的 Lambda 可能(可能)失败:

1) If they are failing because of throttling (more messages to be processed than available Lambda functions), the message (or the whole batch) will be sent back to the Queue and will be tried again once the Visibility Timeout expires, so the retry logic is already built-in for you and scales well. 1) 如果它们由于节流(要处理的消息比可用的 Lambda 函数多)而失败,则消息(或整批)将被发送回队列,并在可见性超时到期后再次尝试,因此重试逻辑已经为您内置并且可以很好地扩展。

2) If they are failing because of bad messages or some error in the code, you can configure a DLQ to send the failed messages to. 2) 如果他们因为坏消息或代码中的错误而失败,您可以配置一个 DLQ 将失败的消息发送到。 This is easy to setup as you only need to tell your Lambda function which DLQ to connect to in case of failure.这很容易设置,因为您只需要告诉您的 Lambda 函数在出现故障时连接到哪个 DLQ。

If you scenario is 1), rest assured your messages won't be lost.如果您的情况是 1),请放心您的消息不会丢失。 If your scenario is 2), just configure a DLQ for further analysis of the failed messages.如果您的场景是 2),只需配置一个 DLQ 以进一步分析失败的消息。

You can also check the official docs to understand Lambda's Retry Behaviour您还可以查看官方文档以了解 Lambda 的重试行为

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

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