Lock duration significance on azure service bus topic subscriptions
Asked Answered
M

1

13

I have been looking at lockdurations and renewlock mechanisms for service bus queue and topics. However it is not clear about what exactly does lock duration mean for topic subscriptions.

For example:

If i have a topic GameScoreUpdate and it has multiple subscribers.

So any message to this topic will be delivered to all the subscribers.

now if On one subscription "Subscription1", i have a lock duration of 30 seconds. but message processing is not complete.then the lock expires?

What happens after this? the other subscribers have already been delivered this message. current subscriber is processing the message.

Whats the significance of lockduration in this case?

Millett answered 1/2, 2018 at 7:13 Comment(0)
S
23

Think of each subscription as an "inbox". Each subscriber gets one. A message is sent to all subscribers, but realistically, it's a clone of the message that is placed into every "inbox", assuming it has a matching criteria.

When a given subscriber tries to process a message from an "inbox" using PeekLock mode, the message is marked as invisible. If there's a failure to process the message in LockDuration time, the message will re-appear in the "inbox" and will be attempted for processing again. Until MaxDeliveryCount attempts are exhausted. In that case, message will be dead-lettered.

This is really needed for competing consumers. I.e. when your subscriber (a process looking at a given subscription/"inbox") is scaled out for processing larger number of messages.

Whats the significance of lockduration in this case?

LockDuration instructs a queue (subscription is a queue after all) to keep message invisible from competing consumers to ensure current processing node can handle it withing time frame defined by LockDuration. Renew lock mechanism ensures that the lock on the currently being processed message is extended to allow longer than LockDuration processing time if needed so. Important thing to remember, lock renewal is not guaranteed to be successful.

Sibship answered 1/2, 2018 at 7:32 Comment(4)
when my subscriber is scaled out from 1 instance to 2 instances, doesn't it mean they are two different clients/subscribers? so we essentially have as many subscribers as many instances? if my queue has a lock duration of 5 mins configured by default. then that's the maximum it can ever have, and i will never need to use renewlock method right? because max lock duration can be 5 mins. if i understand correct.Millett
When a logical subscriber is scaled out, you have still the same logical subscriber, just having multiple instances acting as competing consumers over the same queue. Different logical subscribers have different ASB subscriptions. LockDuration (5 mins or less) means no instance will grab a message until message is either actioned (completed, DLQed, abandoned, etc) or the lock expires. If your processing is done within 5mins, no one else will touch it and you won't need to renew lock. If your processing takes longer than 5mins, that's where renewing is needed. But it's not guaranteed.Sibship
@SeanFeldman, thank you for your answer. Could you elaborate this "renewal is not guaranteed" (I cannot find details in the official docs)? Does it mean that sometimes the renewal can fail due to networking issues, i.e., in some exceptional situations? What is the point of functionality that is known to do what you want only in, say, 50% of cases, depending on the position of the stars? :)Unplumbed
@Unplumbed being a client initiated operation, there's no guarantee the request to extend the lock will be 100% guaranteed. If the time is running out and the client fails to reach the server, c'est la vie...Sibship

© 2022 - 2024 — McMap. All rights reserved.