private static async Task <long> GetSubscriptionActiveMessageCountAsync() { SubscriptionRuntimeProperties subRunTimeProps = await AsbClient.GetSubscriptionRuntimePropertiesAsync(_asbTopicName, _asbSubscriptionName); return(subRunTimeProps.ActiveMessageCount); }
public async Task GetSubscriptionRuntimeInfoTest() { var topicName = nameof(GetSubscriptionRuntimeInfoTest).ToLower() + Recording.Random.NewGuid().ToString("D").Substring(0, 8); var subscriptionName = Recording.Random.NewGuid().ToString("D").Substring(0, 8); var client = CreateClient(); await using var sbClient = new ServiceBusClient(TestEnvironment.ServiceBusConnectionString); await client.CreateTopicAsync(topicName); TopicProperties getTopic = await client.GetTopicAsync(topicName); // Changing Last Updated Time getTopic.AutoDeleteOnIdle = TimeSpan.FromMinutes(100); await client.UpdateTopicAsync(getTopic); SubscriptionProperties subscriptionDescription = await client.CreateSubscriptionAsync(topicName, subscriptionName); // Changing Last Updated Time for subscription subscriptionDescription.AutoDeleteOnIdle = TimeSpan.FromMinutes(100); await client.UpdateSubscriptionAsync(subscriptionDescription); // Populating 1 active message, 1 dead letter message and 1 scheduled message // Changing Last Accessed Time ServiceBusSender sender = sbClient.CreateSender(topicName); await sender.SendMessageAsync(new ServiceBusMessage() { MessageId = "1" }); await sender.SendMessageAsync(new ServiceBusMessage() { MessageId = "2" }); await sender.SendMessageAsync(new ServiceBusMessage() { MessageId = "3", ScheduledEnqueueTime = DateTime.UtcNow.AddDays(1) }); ServiceBusReceiver receiver = sbClient.CreateReceiver(topicName, subscriptionName); ServiceBusReceivedMessage msg = await receiver.ReceiveMessageAsync(); await receiver.DeadLetterMessageAsync(msg.LockToken); List <SubscriptionRuntimeProperties> runtimeInfoList = new List <SubscriptionRuntimeProperties>(); await foreach (SubscriptionRuntimeProperties subscriptionRuntimeInfo in client.GetSubscriptionsRuntimePropertiesAsync(topicName)) { runtimeInfoList.Add(subscriptionRuntimeInfo); } runtimeInfoList = runtimeInfoList.Where(e => e.TopicName.StartsWith(nameof(GetSubscriptionRuntimeInfoTest).ToLower())).ToList(); Assert.True(runtimeInfoList.Count == 1, $"Expected 1 subscription but {runtimeInfoList.Count} subscriptions returned"); SubscriptionRuntimeProperties runtimeInfo = runtimeInfoList.First(); Assert.NotNull(runtimeInfo); Assert.AreEqual(topicName, runtimeInfo.TopicName); Assert.AreEqual(subscriptionName, runtimeInfo.SubscriptionName); Assert.True(runtimeInfo.CreatedAt < runtimeInfo.UpdatedAt); Assert.True(runtimeInfo.UpdatedAt < runtimeInfo.AccessedAt); Assert.AreEqual(1, runtimeInfo.ActiveMessageCount); Assert.AreEqual(1, runtimeInfo.DeadLetterMessageCount); Assert.AreEqual(2, runtimeInfo.TotalMessageCount); SubscriptionRuntimeProperties singleRuntimeInfo = await client.GetSubscriptionRuntimePropertiesAsync(topicName, subscriptionName); Assert.AreEqual(runtimeInfo.CreatedAt, singleRuntimeInfo.CreatedAt); Assert.AreEqual(runtimeInfo.AccessedAt, singleRuntimeInfo.AccessedAt); Assert.AreEqual(runtimeInfo.UpdatedAt, singleRuntimeInfo.UpdatedAt); Assert.AreEqual(runtimeInfo.SubscriptionName, singleRuntimeInfo.SubscriptionName); Assert.AreEqual(runtimeInfo.TotalMessageCount, singleRuntimeInfo.TotalMessageCount); Assert.AreEqual(runtimeInfo.ActiveMessageCount, singleRuntimeInfo.ActiveMessageCount); Assert.AreEqual(runtimeInfo.DeadLetterMessageCount, singleRuntimeInfo.DeadLetterMessageCount); Assert.AreEqual(runtimeInfo.TopicName, singleRuntimeInfo.TopicName); List <TopicRuntimeProperties> topicRuntimePropertiesList = new List <TopicRuntimeProperties>(); await foreach (TopicRuntimeProperties topicRuntime in client.GetTopicsRuntimePropertiesAsync()) { topicRuntimePropertiesList.Add(topicRuntime); } topicRuntimePropertiesList = topicRuntimePropertiesList.Where(e => e.Name.StartsWith(nameof(GetSubscriptionRuntimeInfoTest).ToLower())).ToList(); Assert.True(topicRuntimePropertiesList.Count == 1, $"Expected 1 subscription but {topicRuntimePropertiesList.Count} subscriptions returned"); TopicRuntimeProperties topicRuntimeProperties = topicRuntimePropertiesList.First(); Assert.NotNull(topicRuntimeProperties); Assert.AreEqual(topicName, topicRuntimeProperties.Name); Assert.True(topicRuntimeProperties.CreatedAt < topicRuntimeProperties.UpdatedAt); Assert.True(topicRuntimeProperties.UpdatedAt < topicRuntimeProperties.AccessedAt); Assert.AreEqual(1, topicRuntimeProperties.ScheduledMessageCount); TopicRuntimeProperties singleTopicRuntimeProperties = await client.GetTopicRuntimePropertiesAsync(topicName); Assert.AreEqual(topicRuntimeProperties.CreatedAt, singleTopicRuntimeProperties.CreatedAt); Assert.AreEqual(topicRuntimeProperties.AccessedAt, singleTopicRuntimeProperties.AccessedAt); Assert.AreEqual(topicRuntimeProperties.UpdatedAt, singleTopicRuntimeProperties.UpdatedAt); Assert.AreEqual(topicRuntimeProperties.ScheduledMessageCount, singleTopicRuntimeProperties.ScheduledMessageCount); Assert.AreEqual(topicRuntimeProperties.Name, singleTopicRuntimeProperties.Name); await client.DeleteTopicAsync(topicName); }
private static async Task Main(string[] args) { await Prepare.Stage(connectionString, inputQueue, topicName, subscriptionName); await using var serviceBusClient = new ServiceBusClient(connectionString); await using var queueSender = serviceBusClient.CreateSender(inputQueue); await queueSender.SendMessageAsync(new ServiceBusMessage("Kick off")); await using var topicSender = serviceBusClient.CreateSender(topicName); await topicSender.SendMessageAsync(new ServiceBusMessage("Kick off")); var client = new ServiceBusAdministrationClient(connectionString); NamespaceProperties namespaceInfo = await client.GetNamespacePropertiesAsync(); WriteLine($"Namespace Information about '{namespaceInfo.Name}'"); WriteLine($"{nameof(namespaceInfo.Alias)}: {namespaceInfo.Alias}"); WriteLine($"{nameof(namespaceInfo.CreatedTime)}: {namespaceInfo.CreatedTime}"); WriteLine($"{nameof(namespaceInfo.MessagingSku)}: {namespaceInfo.MessagingSku}"); WriteLine($"{nameof(namespaceInfo.MessagingUnits)}: {namespaceInfo.MessagingUnits}"); WriteLine($"{nameof(namespaceInfo.ModifiedTime)}: {namespaceInfo.ModifiedTime}"); WriteLine($"{nameof(namespaceInfo.Name)}: {namespaceInfo.Name}"); WriteLine($"{nameof(namespaceInfo.MessagingUnits)}: {namespaceInfo.MessagingUnits}"); WriteLine(); QueueRuntimeProperties inputQueueInfo = await client.GetQueueRuntimePropertiesAsync(inputQueue); WriteLine($"Queue Information about '{inputQueue}'"); WriteLine($"{nameof(inputQueueInfo.AccessedAt)}: {inputQueueInfo.AccessedAt}"); WriteLine($"{nameof(inputQueueInfo.CreatedAt)}: {inputQueueInfo.CreatedAt}"); WriteLine($"{nameof(inputQueueInfo.TotalMessageCount)}: {inputQueueInfo.TotalMessageCount}"); WriteLine($"{nameof(inputQueueInfo.ActiveMessageCount)}: {inputQueueInfo.ActiveMessageCount}"); WriteLine($"{nameof(inputQueueInfo.DeadLetterMessageCount)}: {inputQueueInfo.DeadLetterMessageCount}"); WriteLine($"{nameof(inputQueueInfo.ScheduledMessageCount)}: {inputQueueInfo.ScheduledMessageCount}"); WriteLine($"{nameof(inputQueueInfo.TransferDeadLetterMessageCount)}: {inputQueueInfo.TransferDeadLetterMessageCount}"); WriteLine($"{nameof(inputQueueInfo.TransferMessageCount)}: {inputQueueInfo.TransferMessageCount}"); WriteLine($"{nameof(inputQueueInfo.Name)}: {inputQueueInfo.Name}"); WriteLine($"{nameof(inputQueueInfo.SizeInBytes)}: {inputQueueInfo.SizeInBytes}"); WriteLine($"{nameof(inputQueueInfo.UpdatedAt)}: {inputQueueInfo.UpdatedAt}"); WriteLine(); TopicRuntimeProperties topicInfo = await client.GetTopicRuntimePropertiesAsync(topicName); WriteLine($"TopicInformation Information about '{topicName}'"); WriteLine($"{nameof(topicInfo.AccessedAt)}: {topicInfo.AccessedAt}"); WriteLine($"{nameof(topicInfo.CreatedAt)}: {topicInfo.CreatedAt}"); WriteLine($"{nameof(topicInfo.ScheduledMessageCount)}: {topicInfo.ScheduledMessageCount}"); WriteLine($"{nameof(topicInfo.SubscriptionCount)}: {topicInfo.SubscriptionCount}"); WriteLine($"{nameof(topicInfo.Name)}: {topicInfo.Name}"); WriteLine($"{nameof(topicInfo.SizeInBytes)}: {topicInfo.SizeInBytes}"); WriteLine($"{nameof(topicInfo.SubscriptionCount)}: {topicInfo.SubscriptionCount}"); WriteLine($"{nameof(topicInfo.UpdatedAt)}: {topicInfo.UpdatedAt}"); WriteLine(); SubscriptionRuntimeProperties subscriptionInfo = await client.GetSubscriptionRuntimePropertiesAsync(topicName, subscriptionName); WriteLine($"Subscription Information about '{subscriptionName}'"); WriteLine($"{nameof(subscriptionInfo.AccessedAt)}: {subscriptionInfo.AccessedAt}"); WriteLine($"{nameof(subscriptionInfo.CreatedAt)}: {subscriptionInfo.CreatedAt}"); WriteLine($"{nameof(subscriptionInfo.TotalMessageCount)}: {subscriptionInfo.TotalMessageCount}"); WriteLine($"{nameof(inputQueueInfo.TotalMessageCount)}: {inputQueueInfo.TotalMessageCount}"); WriteLine($"{nameof(inputQueueInfo.ActiveMessageCount)}: {inputQueueInfo.ActiveMessageCount}"); WriteLine($"{nameof(inputQueueInfo.DeadLetterMessageCount)}: {inputQueueInfo.DeadLetterMessageCount}"); WriteLine($"{nameof(inputQueueInfo.ScheduledMessageCount)}: {inputQueueInfo.ScheduledMessageCount}"); WriteLine($"{nameof(inputQueueInfo.TransferDeadLetterMessageCount)}: {inputQueueInfo.TransferDeadLetterMessageCount}"); WriteLine($"{nameof(inputQueueInfo.TransferMessageCount)}: {inputQueueInfo.TransferMessageCount}"); WriteLine($"{nameof(subscriptionInfo.SubscriptionName)}: {subscriptionInfo.SubscriptionName}"); WriteLine($"{nameof(subscriptionInfo.TopicName)}: {subscriptionInfo.TopicName}"); WriteLine($"{nameof(subscriptionInfo.UpdatedAt)}: {subscriptionInfo.UpdatedAt}"); WriteLine(); ReadLine(); }