Is there a way to identify if a message is locked in Service Bus?

Viewed 389

From the docs from Message browsing functionality of Azure Service Bus, it says we get InvalidOperationException when we try to access the Lock properties of a message. So we cannot access the lock duration and token details. Is there at least a way or workaround we get to know if it's been locked when we perform a peek?

var client = MessagingFactory.CreateQueueClient("queueName");
BrokeredMessage message = client.Peek(); // Retrieves a locked message and its lock properties returns exception or old lock details depending upon its state
1 Answers

Not really no. You can implicitly find out, but only because you won't be able to receive it in any other mode. Remember that all the messaging is asynchronous.

By the time the information reaches the receiver, the message might be completed or unlocked.

Peek will return the message as is, as if you were the consumer, without any metadata whatsoever. You can't identify locks, as you can't identify any other state of the message (like dead lettered)

Don't forget:

Message browsing, or peeking, enables a Service Bus client to enumerate all messages in a queue or a subscription, for diagnostic and debugging purposes.

You can tell if it's active, deferred or scheduled but that's about it.

Important - Don't assume that if you can't receive it in peeklock mode that it's locked or vice versa. Anything could have happened in between the two rest api calls.

Related