amazon-web-services - SQS仅发送一次消息

标签 amazon-web-services amazon-sqs

假设我有100个线程从相同的sqs读取-是否可以确保每个消息最多发送一次?是否可以多次传递相同的消息?我找不到有关此问题的清晰文档。 s

最佳答案

更新2016年11月17日: FIFO queueing with guaranteed-once delivery今天才发布(最初发布此答案后将近两年),并且SQS现在支持一次发送。详细信息如下:

  • 您需要创建一个FIFO Queue
  • 重复数据删除检查MessageDeduplicationId作为队列消息的属性,并通过检查MessageDeduplicationId来防止重复消息在5分钟的重复数据删除间隔内发送和接收重复消息。
  • 如果在FIFO队列上显式启用了基于内容的重复数据删除,则MessageDeduplicationId将使用消息正文的SHA-256哈希值自动生成(仅内容,而不是属性)。
  • 如果未启用基于内容的重复数据删除,则必须在发送时为MessageDeduplicationId显式设置自己的任意值。否则,SendMessage将失败并显示错误。

  • 可以在creating a queueupdating the queue' attributes时启用基于内容的重复数据删除。

    SendMessageReceiveMessage文档中有关MessageDeduplicationId的更多详细信息。

    ,2016年11月17日之后,这仍然适用于标准(非FIFO)队列:

    由于SQS中标准(非FIFO)队列的分布式性质,因此保证“至少”一次。

    FAQ:

    Q: How many times will I receive each message?

    Amazon SQS is engineered to provide “at least once” delivery of all messages in its queues. Although most of the time each message will be delivered to your application exactly once, you should design your system so that processing a message more than once does not create any errors or inconsistencies.



    有关at least once交付的更多信息:

    Amazon SQS stores copies of your messages on multiple servers for redundancy and high availability. On rare occasions, one of the servers storing a copy of a message might be unavailable when you receive or delete the message. If that occurs, the copy of the message will not be deleted on that unavailable server, and you might get that message copy again when you receive messages. Because of this, you must design your application to be idempotent (i.e., it must not be adversely affected if it processes the same message more than once).



    如果您确实需要保证应用程序中的“至多一次”处理,则可能希望您的应用程序检查unique identifiers of SQS messages而不处理之前或当前正在处理的消息ID。

    关于amazon-web-services - SQS仅发送一次消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28111941/

    相关文章:

    amazon-web-services - SNS 中的时间戳 -> SQS 消息体

    node.js - Elastic Beanstalk 在配置菜单中没有负载均衡器设置

    sockets - 如何从 AWS EC2 实例 ping 到我的本地机器?

    amazon-web-services - 使用 ebextensions 配置在弹性 beantalk 上安装 ffmpeg

    python - 运行除 fabfile.py 之外的重命名的结构文件和无密码 ssh

    amazon-web-services - 无法在 SQS FIFO 上触发 lambda

    java - AWS Java SDK SQSlistener 端点问题

    android - AWS iOS/Android SDK 大小问题

    amazon-web-services - 如何让 VPC 端点在 Docker 容器中工作?

    node.js - sqs 在接收消息时没有给我 MessageAttributes