简体   繁体   English

AWS SQS - 如何有条件地决定是否应将消息移动到 DLQ?

[英]AWS SQS - How to conditionally decide whether a message should be moved to the DLQ?

I know SQS has the maxReceiveCount and once the message has been consumed and failed this amount of times, then the message is moved to the DLQ.我知道 SQS 有 maxReceiveCount,一旦消息被使用并失败了这么多次,消息就会被移到 DLQ。 That's working currently.目前正在工作。

However, there are certain errors which I would want to go back in my source queue indefinitely eg if we get a 5XX error from an API we are invoking.但是,有些错误我希望 go 无限期地返回到我的源队列中,例如,如果我们从正在调用的 API 中收到 5XX 错误。 This is very likely to be temporary, and so we would want to retry these until they are successful.这很可能是暂时的,因此我们希望重试这些直到它们成功。

Now if these 5XX failed messages do go to the DLQ, it's not the end of the world, but it requires a manual redrive.现在,如果这 5XX 条失败消息对 DLQ 执行 go,这还不是世界末日,但需要手动重新驱动。

Is there a known solution or aws feature which allows for conditionally moving messages to the DLQ depending on the error received?是否有已知的解决方案或 aws 功能允许根据收到的错误有条件地将消息移动到 DLQ?

I'm not sure this is possible.我不确定这是可能的。 I've read the documentation and can't find anything that hints at how to achieve this.我已经阅读了文档,但找不到任何关于如何实现这一点的提示。

Since you didn't provide much detail about the way you process the message, I'm assuming you are using a lambda that would make the call against that API you mentioned.由于您没有提供有关处理消息的方式的详细信息,我假设您使用的是 lambda,它会针对您提到的 API 进行调用。

If that's the case, based on the response code, you could decide to put back the message in the queue (as if it is a new message) and return success so that the message is not duplicated.如果是这种情况,根据响应代码,您可以决定将消息放回队列中(就像它是一条新消息一样)并返回成功,这样消息就不会重复。

I'd also recommend to have a custom counter as part of your message to not retry infinite number of time and be stuck in a situation where your lambda process the same message over and over.我还建议将自定义计数器作为消息的一部分,以免重试无限次并陷入 lambda 一遍又一遍地处理相同消息的情况。

A preferable approach would be to set Maximum receives to 1000 for DLQ.更好的方法是将 DLQ 的最大接收数设置为 1000。 You could throw an error based on the response code in your lambda and let SQS moving the message to the DLQ once it reached 1000. 1,000 it is quite a lot of retries..您可以根据 lambda 中的响应代码抛出错误,并让 SQS 在消息达到 1000 时将消息移动到 DLQ。1,000 是相当多的重试。

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

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