Search code examples
azureazureservicebusazure-servicebus-queues

Azure Service Bus - TTL with ScheduledEnqueueTimeUtc


A queue is setup with a TTL (time to live) of 5 minutes.

When you add message with a ScheduledEnqueueTimeUtc of 1 minute from UtcNow, will the message expire in 5 minutes or 6?

My assumption is 6 because I would expect the TTL 'countdown' to 'start' once the message was 'active' in the Queue and a message is not active until the scheduled enqueue time has passed.

Then if you enqueue a message for 6 minutes, it will expire after 11 minutes.

Is my assumption correct?


Solution

  • Your assumption is correct. There are a couple of properties on a message:

    ScheduledEnqueueTimeUtc time for the message to appear set by user code TimeToLive time for message to live set by either user or the entity (in your case a queue) EnqueuedTimeUtc - read-only time when message was received by the broker ExpiresAtUtc - calculated time when message will expire

    If message is en-queued at time X, TTL on the queue is 5 minutes and not lower TTL specified for the individual message, then the message will appear on the queue at X + 1 time. I.e. EnqueuedTimeUtc will be X + 1. With TimeToLive 5 minutes, ExpiresAtUtc will be calculated as X + 1 + 5.

    Therefore a message en-queued for 6 minutes from now (X), it will not expire before X + 11.