在达到可见性超时并且消息已重新排队后删除

Delete after visibility timeout has been reached and the message has been requeued

假设我有一份工作需要 10 秒到 40 秒。
可见性超时设置为 30 秒。

一项工作在 40 秒内完成,因此消息返回到队列中,其他工作人员可以看到。

用了 40 秒的工作人员现在删除了消息。

  1. 是否删除成功?
  2. 作业会从队列中消失吗?

谢谢。

如果消费者保留一条消息直到其可见性超时过期,将其删除将其从队列中删除...通常.

DeleteMessage

Deletes the specified message from the specified queue. You specify the message by using the message's receipt handle and not the MessageId you receive when you send the message. Even if the message is locked by another reader due to the visibility timeout setting, it is still deleted from the queue.

到目前为止,还不错吧?

但有一个明显的警告。

Note

The receipt handle is associated with a specific instance of receiving the message. If you receive a message more than once, the receipt handle you get each time you receive the message is different. If you don't provide the most recently received receipt handle for the message when you use the DeleteMessage action, the request succeeds, but the message might not be deleted.

它“可能不会”被删除的确切原因没有解释,但我想到了以下几个原因:

可能是SQS不记得删除句柄的无限回归。如果消费者收到了相同的消息,比如 576 次不同的时间,那么(例如)第 16 个顺序发出的删除句柄可能很久以前就被 SQS 丢弃了,因为已经过去了那么多时间......

或者,这可能是 SQS 分布式架构的一个怪癖。对于 non-FIFO 队列,服务的设计是在发生任何内部不一致的情况下,SQS 将始终倾向于确保“至少一次”传递和删除消息,并且从操作的角度来看,2交付比 0 次交付更可取。

这里的含义是,最后一个收到消息的消费者应该删除它,而较早收到消息并持有太久的消费者的任何删除尝试也可能会成功。

引用来自 SQS API Reference: DeleteMessage.