使用部分批处理响应使 SQS 消息再次可见
假设:
- AWS Lambda 以 10 个元素批量处理来自 AWS SQS FIFO 队列的消息,具有 25 个可用消息组 ID(以随机方式分配),
- 单个消息的处理需要约 30-60 秒
- SQS 消息可见性超时已设置到 10 分钟
- 集成触发器 Lambda-SQS 已启用“部分批量响应”
当 Lambda 返回带有失败消息 ID 的部分批量响应时,例如:
{
"batchItemFailures": [
{
"itemIdentifier": "d4c7c57f-c12c-4639-abe3-3a0d37690790"
}
]
}
成功处理的消息将从中删除队列。 但是,批次中失败的消息仍在等待可见性超时,而不是立即对消费者可见。失败消息的行为是否正确?或者让它们立即可见的唯一方法是调用 SQS API 并将可见性超时更改为 0?
Assuming:
- there is AWS Lambda that processes messages in 10-elements batches from AWS SQS FIFO queue with 25 available message group ids (assign in a random fashion)
- the processing of a single message takes ~30-60 sec
- SQS message visibility timeout is set to 10 min
- integration trigger Lambda-SQS has 'Partial batch response' enabled
When Lambda returns a partial batch response with ids of the failed messages, e.x.:
{
"batchItemFailures": [
{
"itemIdentifier": "d4c7c57f-c12c-4639-abe3-3a0d37690790"
}
]
}
The successfully processed messaged are deleted from the queue.
However, the failed messages from the batch are still waiting for the visibility timeout instead of being made visible to the consumers immediately. Is the behaviour for failed messages correct? Or the only way to make them visible immediately is to call SQS API and change visibility timeout to 0?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

虽然我不能谈论 FIFO SQS 队列,但我可以说我在标准 SQS 队列中看到了这种行为。
我假设在 batchItemFailures 中返回的项目将立即设置为可见,但它们确实似乎保持在飞行中,直到 VisibilityTimeout 过期。
我的解决方案是在返回 batchItemFailures 之前通过 SQS API 手动将消息可见性超时更改为 0。
While I cant speak for a FIFO SQS queue, I can say that I am seeing this behavior with a Standard SQS queue.
I assumed that items returned in the batchItemFailures would immediately be set to visible, but they do indeed seem to remain in flight until their VisibilityTimeout expires.
My solution was to manually change the message visibility timeout to 0 via the SQS API before returning the batchItemFailures.