philmckendry
philmckendry

Reputation: 565

Azure service bus subscription metrics

I am trying to find the best way to see the last date a subscription in a topic was accessed via c# (SDK or otherwise) i.e. to purge the queue if not accessed in over x hours. I know there is that functionality built into the service bus explorer but have not been able to find any SDK functionality. If anyone could point me in the right direction it would be appreciated.

Service Bus Explorer example

Upvotes: 2

Views: 587

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136366

Please see the code below. It uses Azure.Messaging.ServiceBus SDK. The properties you're interested in is available in SubscriptionRuntimeProperties class.

using System;
using System.Threading.Tasks;
using Azure.Messaging.ServiceBus.Administration;

namespace ConsoleApp1
{
    
    class Program
    {
        static async Task Main(string[] args)
        {
            string connectionString =
                "connection-string";
            string topicName = "topic-name";
            string subscriptionName = "subscription-name";
            ServiceBusAdministrationClient administrationClient = new ServiceBusAdministrationClient(connectionString);
            var result = await administrationClient.GetSubscriptionRuntimePropertiesAsync(topicName, subscriptionName);
            Console.WriteLine(result.Value.AccessedAt.ToString("yyyy-MM-ddTHH:mm:ss"));
        }
    }
}

Upvotes: 3

Related Questions