简体   繁体   English

AWS Lambda + SQS (Java)。 Lambda 已成功完成工作,但未从 SQS 中删除消息。 是否应再次发送此消息以进行处理?

[英]AWS Lambda + SQS (Java). Lambda successfully was finished work but didn't delete message from SQS. Should this message be sent to process again?

I faced with such aws sqs behavior.我遇到了这种 aws sqs 行为。

I have lambda is triggered by api gateway.我有 lambda 是由 api 网关触发的。 In this lambda in some cases i need to reprocess incoming request.在此 lambda 中,在某些情况下我需要重新处理传入的请求。 So in such cases i send incoming request as message to sqs with delay (30s).因此,在这种情况下,我将传入请求作为消息发送到延迟(30 秒)的 sqs。 In sqs "Default Visibility Timeout" set up to 1 min and and linked dlq queue.在 sqs 中,“默认可见性超时”设置为 1 分钟并链接 dlq 队列。

In lambda i have next logic:在 lambda 我有下一个逻辑:

  1. When i get request by api gateway and my lambda decides to reprocess it, then it first time sends message to sqs for reprocessing.当我收到 api 网关的请求并且我的 lambda 决定重新处理它时,它第一次将消息发送到 sqs 进行重新处理。 Them my lambda gets message back in 30s.他们我的 lambda 在 30 秒内收到消息。 Ok.好的。

  2. But when during this reprocessing i need to reprocess it again, my lambda does nothing and simply finishes.但是当在这个重新处理过程中我需要再次重新处理它时,我的 lambda 什么都不做,只是完成了。 Because in aws docs says that for the message acknowledge in sqs i need to send the delete request.因为在 aws 文档中说对于 sqs 中的消息确认,我需要发送删除请求。 Lambda doesn't send it. Lambda 不会发送它。 I thought it should work.我认为它应该工作。 But not.但不是。

  3. Then my lambda doesn't get this message again and also i don't see the message in the queue.然后我的 lambda 不会再次收到此消息,而且我也没有在队列中看到该消息。

  4. But when i throw the exception instead of simply finish work, lambda gets message again.但是当我抛出异常而不是简单地完成工作时,lambda 再次收到消息。

Is this really need to throw the exception for getting message from sqs to lambda again instead of simply not send the delete request for message.这是否真的需要抛出异常以再次从 sqs 获取消息到 lambda,而不是简单地不发送消息的删除请求。

Thank you!谢谢!

As you wrote docs for SQS says messages need to be deleted from the queue to be considered as handled.正如您为 SQS 编写的文档所说,需要从队列中删除消息才能被视为已处理。 Otherwise they are considered not handled and SQS will try to deliver them again until configured limit is reached.否则,它们将被视为未处理,并且 SQS 将尝试再次传送它们,直到达到配置的限制。

If AWS docs says something and AWS works respectively, then there is no need to ask if AWS docs are really really correct.如果 AWS 文档说了些什么并且 AWS 分别有效,那么就没有必要问 AWS 文档是否真的正确。

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

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