Azure inter-role synchronization

ぐ巨炮叔叔 提交于 2019-12-05 09:05:01

I've just written a couple blog posts about using blob leases to do this sort of thing. See http://blog.smarx.com/posts/managing-concurrency-in-windows-azure-with-leases and http://blog.smarx.com/posts/building-a-task-scheduler-in-windows-azure.

dunnry is spot-on: queues work great for preventing multiple instances from working on the same work item. When you call GetMessage, the message you retrieve is now invisible for the timespan you specify (default: 30 seconds). In that timespan, no other reader can retrieve this queue message.

Having said that: You need to ensure your processing is idempotent. In the case where your processing takes longer than the invisibility timespan, the message becomes visible again. At this point, the original reader cannot delete the message, and someo other reader can read the message (making it once again invisible). In this case, it's possible that you re-process the same message. You'll need to carefully set your timeout window to avoid this as a general rule.

Note: Each CloudQueueMessage has aDequeueCount property, so you can determine if the message has been seen more than once (and so you can also deal with poison messages).

CloudFX has a PrimaryInstanceManager class that can be used for some of these scenarios.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!