Azure 队列唯一消息
我想确保不会多次将消息插入队列。我可以使用任何 ID/名称来强制唯一性吗?
I would like to make sure that I don't insert a message to the queue multiple times. Is there any ID/Name I can use to enforce uniqueness?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
vtortola 几乎涵盖了它,但我想添加更多细节来解释为什么它至少一次交付。
当您读取队列项目时,它不会从队列中删除;而是会被删除。相反,它变得不可见,但保留在队列中。该隐形时间默认为 30 秒(最长:2 小时)。在此期间,将项目从队列中取出的代码有足够的时间来处理队列消息中的任何命令并删除队列项目。
假设队列项在超时时间到达之前被删除,则一切正常。但是:一旦达到超时时间,队列项将再次变得可见,并且保存队列项的代码可能不再删除它。在这种情况下,其他人可以读取同一队列消息并重新处理该消息。
由于队列消息可能会超时,并且可能会重新出现:
有关 get-queue 低级 REST API 的更多详细信息,请参见此处。这将使您更深入地了解 Windows Azure 队列消息处理。
vtortola pretty much covered it, but I wanted to add a bit more detail into why it's at least once delivery.
When you read a queue item, it's not removed from the queue; instead, it becomes invisible but stays in the queue. That invisibility period defaults to 30 seconds (max: 2 hours). During that time, the code that got the item off the queue has that much time to process whatever command was in the queue message and delete the queue item.
Assuming the queue item is deleted before the timeout period is reached, all is well. However: Once the timeout period is reached, the queue item becomes visible again, and the code holding the queue item may no longer delete it. In this case, someone else can read the same queue message and re-process that message.
Because of the fact a queue message can timeout, and can re-appear:
More details on the get-queue low-level REST API is here. This will give you more insight into Windows Azure queue message handling.
Azure 队列不确保消息顺序和消息的唯一性。消息将被“至少处理一次”,但没有什么可以确保它不会被处理两次,因此它不能确保“最多一次”。
您应该准备好两次收到同一条消息。您可以将 ID 作为数据的一部分放入消息正文中。
Azure queues doesn't ensure message order and either message uniqueness. Messages will be processed "at least once", but nothing ensures it won't be processed twice, so it doesn't ensure "at most once".
You should get ready to receive the same message twice. You can put an ID in the body of the message as part of your data.