是否有可能在消息被处理之前就从 SQS AWS 服务中取出消息?

Is it possible to dequeue a message from SQS AWS service even before it gets processed?

我刚开始使用AWS的SQS服务。好吧,我知道我们可以使用收到消息时得到的 ReceiptHandle 删除进程,但我想删除队列中的消息或将其移至死信队列。 是否可能因为文档中没有提及它?如果是,请给我一个提示或代码或任何 link。 谢谢

比如有这个使用ReceiptHandle删除消息的方法。

for (Message m : messages) {
    sqs.deleteMessage(queueUrl, m.getReceiptHandle());
}

经过更多研究,我在 AWS SQS 开发人员指南上找到了这个。

Every time you receive a message from a queue, you receive a receipt handle for that message. This handle is associated with the action of receiving the message, not with the message itself. To delete the message or to change the message visibility, you must provide the receipt handle (not the message ID). Thus, you must always receive a message before you can delete it (you can't put a message into the queue and then recall it). The maximum length of a receipt handle is 1,024 characters.`

虽然您无法在不阅读邮件的情况下有选择地删除邮件,但您可以使用“清除队列”功能一次性删除队列中的所有邮件。

更多详细信息列于 delete-all-messages-in-an-amazon-sqs-queue

如果您想以编程方式执行此操作,那么各种 SDK 也都支持。

Here 是如何使用 Python SDK

执行此操作的示例