azure-service-bus icon indicating copy to clipboard operation
azure-service-bus copied to clipboard

How to determine if a message is deferred?

Open mlbiam opened this issue 2 years ago • 8 comments

Description

I create a Peek client for my queue:

ServiceBusReceiverClient peekClient = new ServiceBusClientBuilder()
            .connectionString(conString)
            .receiver()
            .queueName(myQueue)
            .buildClient();

and retrieve the messages:

ServiceBusReceivedMessage m = null;
        
while ((m = peekClient.peekMessage()) != null) {
    System.out.println(m.getApplicationProperties());
}

There's no property that indicates if a message is deferred though. When I look at a message in servicebusexplorer I can see it's state as Deferred, but there's no "state" property anywhere I can find.

Actual Behavior

  1. Peek messages, no indication of the message's "state"

Expected Behavior

  1. Property of some kind or method of knowing if a message is in deferred state.

mlbiam avatar Jul 30 '21 14:07 mlbiam

I think that function peekMessage() does not retrieve deferred messages. You have to use peekMessage(long sequenceNumber). It's the same as function receiveMessages(int maxMessages) and receiveDefferedMessage(long sequenceNumber), which states in javadoc Receives a deferred message. Deferred messages can only be received by using sequence number.

TomasTokaMrazek avatar Aug 16 '21 11:08 TomasTokaMrazek

The service side doesn't support this feature. Please up-vote feature request here: https://github.com/Azure/azure-service-bus/issues/95

SeanFeldman avatar Aug 17 '21 03:08 SeanFeldman

I feel like this particular behaviour is a bug rather than the absence of the referenced feature. I agree the expected behavior of Peek is to get the next active message. Scheduled messages shouldn't be included until they are active and waiting to be received.

I also think the fact that the EnqueuedTime for the scheduled message when should peeked should so the time it will become active, but it doesn't, it shows the time you peeked. When you receive the message later through a regular receive that time has been updated to the scheduled time.

ciaranodonnell avatar Aug 23 '21 21:08 ciaranodonnell

We have an item on our backlog to give back the state of a message when peeking, however we don't have specific timelines for this yet.

EldertGrootenboer avatar Apr 01 '22 19:04 EldertGrootenboer

We have an item on our backlog to give back the state of a message when peeking

That's great, 👏

however we don't have specific timelines for this yet.

In that case, the issue should remain open until it's resolved. Having a comment with an updated status is great to indicate that the issue is not in limbo. Having the issue opened prevents new issues like this from being raised and allows folks to subscribe to get notified when the work is completed, and the feature is available.

SeanFeldman avatar Apr 01 '22 19:04 SeanFeldman

I am just checking the source code. I see that the issue was fixed sometime last year, and client can read State property in AMQP message annotations with name "'x-opt-message-state". Now SDKs have to read this annotation and set it on the returned Message object.

yvgopal avatar Aug 04 '22 18:08 yvgopal

Thank you for your feedback on this item. We are currently doing active development on this feature, and expect to have more to share around its release in the next couple of months.

EldertGrootenboer avatar Oct 13 '23 19:10 EldertGrootenboer