I know (reading the msdn documentation here) that Windows Azure Storage Queues use a lease-based exclusive access strategy to the messages and Azure Service Bus Queues use a lock-based one. In both I can set the maximum duration of lock/lease. So, which are the most important differences between these two methods? Could someone provide a clear/short example? Thanks.
In both cases when you read a message, the message is locked (or leased) and others cannot access it. Difference is, for Storage Queue you can define the lease duration for the message itself (by default is 30 seconds, it can be up to 7 days) so you as the client (publisher) can specify this when pushing the message to the queue; whereas for Service Bus the lock duration is defined at the queue or topic level (default is also 30 seconds), so you as a client (publisher) cannot control this.
My understanding is that lease-based has a time limit, but lock-based does not have.
For example, the duration of a lease can be 30s long, before current user releases it or the duration expires, others cannot get the lease to access the resource. But after 30s, anyone can get it and access the resource. (Of course, you can set the duration to be infinite.)
For lock-based, if the current user does not release the lock, no one can get the lock.
Managing Concurrency in Windows Azure with Leases
@nop's answer is correct.
Leases have auto-timeout feature, so in case if a service which is holding a resource dies, the resource is freed after the set-timeout and the scenario of deadlock is avoided. They also have renew capability.
© 2022 - 2024 — McMap. All rights reserved.