2

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
Deepak
  • 2,660
  • 2
  • 8
  • 23
  • The question is why do you need to know? Peeking is not receiving. What are you trying to accomplish? – Sean Feldman Dec 25 '20 at 21:00
  • I'm trying to write a logic to delete from the beginning of the queue using sequence number order. If its a deferred message, peek helps me get the sequence number to delete immediately (by catching exceptions when its expired/locked). If its an active message, I can receive and delete. For example: If I am supposed to delete only first 10 messages, and when I peek the first message in the queue (consider this is locked message and there are no more active messages in the top 10 messages), I assume there is an active message and receive a message somewhere below the 10th message. – Deepak Dec 26 '20 at 06:37

1 Answers1

1

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.

Athanasios Kataras
  • 25,191
  • 4
  • 32
  • 61
  • Yeah thanks @Athanasios, maybe if its a feature implemented in future, this would be an added advantage. As you mentioned everything is asynchronous, but at that exact point of a snapshot, what's going on with the messages is what I was looking at. Thanks. – Deepak Dec 25 '20 at 17:47