Search code examples
queueazureservicebus

What does LockDuration means in Azure Service Bus


I have a consumer that has been subscribed to a queue in Azure Service Bus. From the consumer end, I have set LockDuration to 2min.

So, when a message arrives in the queue and the consumer picks that, does it means:

  • The consumer will be locked for 2min?
  • The consumer will not pick any new messages before 2min? Even if the consumer was able to process the message within seconds?
  • The message will not be picked by any other consumers for at-least 2min?

Solution

  • The lock duration is the amount of time that a consumer has exclusive access to a specific message without explicitly asking for more time (renewing the lock) or indicating that they are done (settling the message). If the amount of time indicated by the lock duration passes and the consumer hasn't renewed or settled, the lock expires, and Service Bus makes the message available for another consumer to read.

    More information is available in: Message transfers, locks, and settlements.

    To address your bullet points:

    • The consumer will be locked for 2min?

    The consumer is not locked, the message is. The consumer is free to perform other operations, including receiving messages in parallel.

    • The consumer will not pick any new messages before 2min? Even if the consumer was able to process the message within seconds?

    The consumer can continue to ask for more messages in parallel. If the consumer processes a message in seconds, it should complete/abandon/dead-letter the message which indicates to Service Bus that the consumer is done with the message.

    • The message will not be picked by any other consumers for at-least 2min?

    This is true for the case where the consumer that holds the lock does not renew it or settle a message. More information is available in the link above.