亚马逊 SQS getMessageID

Amazon SQS getMessageID

Amazon SQS 仅提供至少一次配送。所以我必须证明消息是否是第二次发送。是否可以使用 getMessageID() 方法识别唯一消息的删除?我可以将字符串存储在数据结构中并匹配它吗?

当你receive an SQS message, there are two relevant items sent along with the message:

MessageId

A unique identifier for the message. Message IDs are considered unique across all AWS accounts for an extended period of time.

Type: String

Required: No

ReceiptHandle

An identifier associated with the act of receiving the message. A new receipt handle is returned every time you receive a message. When deleting a message, you provide the last received receipt handle to delete the message.

Type: String

Required: No

因此,要识别重复邮件,您需要:

  • 存储您收到的 MessageIds
  • 检查您的 MessageId 存储中是否已存在新消息的 MessageId

您也可以存储 ReceiptHandles,但如果您只关心接收一次,那么我认为存储 MessageIds 就足以暗示它已经被接收过一次。

一旦识别出重复邮件,您可以根据需要使用重复邮件的 ReceiptHandle delete the duplicate message