假设我有100个线程从相同的sqs读取-是否可以确保每个消息最多发送一次?是否可以多次传递相同的消息?我找不到有关此问题的清晰文档。 s
最佳答案
更新2016年11月17日: FIFO queueing with guaranteed-once delivery今天才发布(最初发布此答案后将近两年),并且SQS现在支持一次发送。详细信息如下:
MessageDeduplicationId
作为队列消息的属性,并通过检查MessageDeduplicationId
来防止重复消息在5分钟的重复数据删除间隔内发送和接收重复消息。 MessageDeduplicationId
将使用消息正文的SHA-256哈希值自动生成(仅内容,而不是属性)。 MessageDeduplicationId
显式设置自己的任意值。否则,SendMessage将失败并显示错误。 可以在creating a queue或updating the queue' attributes时启用基于内容的重复数据删除。
SendMessage和ReceiveMessage文档中有关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/