1

工作原理:使用适用于 .Net 的 AWS-SQS 开发工具包,我能够接收消息批次并在消息可见性计时器窗口中删除单个消息。我也不能做任何事情并有效地将消息重新排队,如果它重新排队了配置的次数,那么它就会变成死信。

What doesn't work: I'm trying to do the same thing using a Lambda. I've created a trigger which works meaning SQS triggers the lambda sending it a batch of messages. These messages seem to get deleted from the queue automatically when this happens. I've no control over deleting an individual message or requeuing it.

Throwing an exception in the lambda seems to get all the messages in the batch to remain in the queue. Is there a more elegant way to do this and also is there a way to do it for individual messages instead of the entire batch?

4

2 回答 2

1

当您使用SQS Lambda 触发器时,如果处理成功,您的消息将自动从队列中删除。

如果您愿意,您可以从 SQS 轮询消息,而不是让消息触发您的 Lambda。为了做到这一点,只需不要为您的 Lambda 函数配置触发器,而是让它通过Cloud Watch Event每 X 时间执行一次。每次执行时,您都会轮询您的 SQS 队列以获取新消息。不过,我真的不明白您为什么要这样做,因为触发和自动删除消息非常方便。如果您想将失败的消息发送到 DLQ,只需在源 SQS 队列本身上设置 DLQ。然后您可以自定义maxReceiveCount,一旦达到此阈值,消息将转到配置的 DLQ。

从文档:

如果一条消息多次处理失败,Amazon SQS 可以将其发送到死信队列。在源队列上配置死信队列以保留处理失败的消息以进行故障排除。将队列的重新驱动策略上的 maxReceiveCount 设置为至少 5,以避免由于节流而将消息发送到死信队列。

于 2019-03-12T08:40:12.887 回答
0

如果要重新排队,请将批处理大小设置为 1 并引发异常。

于 2021-09-22T21:57:28.000 回答