'get Azure Service Bus Queue active message count by SessionId using C#

I want to get the count of the messages from an Azure Service Bus Queue, using the SessionId of the messages.
I found how to count them without filtering by Session IDs here - Get queue message count using Microsoft.Azure.Management.ServiceBus, but I really need to count the messages with a specific SessionId.



Solution 1:[1]

You can get the count of the messages from an Azure Service Bus Queue as said, but by using the particular SessionId you cannot get the messages count.

The Azure.Messaging.ServiceBus. ServiceBusSessionReceiver is responsible for receiving ServiceBusReceivedMessage and settling messages from session-enabled Queues and Subscriptions.

public class ServiceBusSessionReceiver : 
Azure.Messaging.ServiceBus.ServiceBusReceiver

By using the default Properties of this class, we can get the details of SessionId and others like PrefetchCount, IsClosed etc..

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RajkumarMamidiChettu-MT