Microsoft.Azure.ServiceBus How to get Message State

Viewed 247

I am working on an azure function V2 that peeks the messages from the service bus. In this function I would like to know the state of the messages (Active, Deferred, Scheduled)

I know that Microsoft.ServiceBus.Messaging.BrokeredMessage has a State property.

But I am using Microsoft.Azure.ServiceBus. So How do I get the state of Microsoft.Azure.ServiceBus.Message?

Just an example function that explains my need:

[FunctionName("GetStates")]
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = "getstates")] HttpRequest req, ILogger log)
{
    var result = new Dictionary<string, int>() /** string: state, int: counter **/

    receiver = new MessageReceiver("MyConnectionString", EntityNameHelper.FormatSubscriptionPath("MyTopic", "MySubscription"));
    var messages = await receiver.PeekBySequenceNumberAsync(receiver.LastPeekedSequenceNumber, 50);

    // How to get the states???

    return new OkObjectResult(result);
}
1 Answers

When the BrokeredMessage type from track 0 SDK was moved to the Message type in track 1 (Microsoft.Azure.ServiceBus), the MessageState was not implemented. While I don't know the rationale behind that decision or wherever this was just missed out by mistake. You could raise an issue with the Azure SDK using the Azure SDK repository issue tracker here.

Related