简体   繁体   English

如何防止 AWS Lambda 从 SQS 队列中删除消息

[英]How to prevent AWS Lambda from deleting message from SQS queue

I have a Lambda function, which will be sending SNS notification when a message is sent to SQS Queue.我有一个 Lambda function,它将在向 SQS 队列发送消息时发送 SNS 通知。 But i observe that Lambda will delete the message from queue once it has processed it and its been mentioned here但我观察到 Lambda 将在处理完消息后从队列中删除消息,并在此处提及

Is there a way i can make the lambda fail, without actually throwing a new Exception in java.有没有办法让 lambda 失败,而实际上不会在 java 中引发新的异常。

From you description, it seems that you should consider using fan-out scenario for your use-case:根据您的描述,您似乎应该考虑为您的用例使用扇出场景:

The "fanout" scenario is when an Amazon SNS message is sent to a topic and then replicated and pushed to multiple Amazon SQS queues , HTTP endpoints, or email addresses. “扇出”场景是指将 Amazon SNS 消息发送到主题,然后复制并推送到多个 Amazon SQS 队列、HTTP 终端节点或 email 地址。

在此处输入图像描述

In this scenario, your SNS would publish a message to two SQS queues .在这种情况下,您的 SNS 会将消息发布到两个 SQS 队列 Subsequently, each team would have its own messages to work, and you wouldn't need to forcefully terminate your lambda to keep a processed message in a single queue.随后,每个团队都有自己的消息可以工作,您无需强制终止 lambda 即可将已处理的消息保留在单个队列中。

By default, SQS to Lambda integration means that messages in que will become invisible once the function begins processing it, and will be deleted from the que once the function has completed.默认情况下,SQS 到 Lambda 集成意味着一旦 function 开始处理队列中的消息将变得不可见,一旦 ZC1C425268E68385D1AB5074C17A94F14 完成,队列中的消息将从队列中删除。

If the function fails (bad exit), then the message will go back to 'visible', and will be processed once again by a new lambda invocation.如果 function 失败(退出错误),则消息将 go 恢复为“可见”,并将由新的 lambda 调用再次处理。 This will go-on until whatever is configured in your re-drive policy.这将一直持续到您的重新驱动策略中配置了任何内容。

In any case, after about 4 days, messages will start to be purged off the que, the SQS que is not a permanent storage place.无论如何,大约 4 天后,消息将开始从队列中清除,SQS 队列不是永久存储位置。 You cannot use SQS as permanent storage.您不能将 SQS 用作永久存储。

A short answer to your question is to fail the invocation by exiting with a non-zero status -- but beware, the message will be reprocessed, unless you have a redrive policy that will push it into the DLQ.对您的问题的简短回答是通过以非零状态退出来使调用失败 - 但请注意,消息将被重新处理,除非您有将其推入 DLQ 的重新驱动策略。

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

相关问题 将数据从AWS Lambda发送到SQS队列时重置连接 - Connection reset while sending data from AWS Lambda to SQS queue 从 Lambda 向 SQS 发送跨 AWS 账户消息 - Send cross AWS account message from Lambda to SQS 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? 从AWS上的SQS队列连续轮询 - Polling Continuously from a SQS queue on AWS AWS SQS Java。 并非所有消息都从SQS队列中检索 - AWS SQS Java. Not all messages are retrieved from the SQS queue 从AWS Elastic Transcoder获得SQS队列消息时,保留字符将用“ _”替换 - Reserved Characters are replaced with “_” when get a SQS Queue message from AWS Elastic Transcoder 在 java 中从本地向 SQS 队列发送消息失败 - Sending message to a SQS queue fails from local in java 如何使用Spring Integration处理来自AWS SQS FiFo队列的10多个并发消息 - How to process more than 10 concurrent messages from an AWS SQS FiFo queue using Spring Integration 使用 Java 从 AWS Lambda 访问 SQS 时超时 - Timeout when accessing SQS from AWS Lambda using Java AWS Lambda不会从队列中删除消息 - AWS Lambda not removing messages from the queue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM