public static async Task ReportNumberOfMessages(string connectionString, string destination) { var client = new ServiceBusAdministrationClient(connectionString); QueueRuntimeProperties info = await client.GetQueueRuntimePropertiesAsync(destination); Console.WriteLine($"#'{info.ActiveMessageCount}' messages in '{destination}'"); }
public async Task StopAsync(CancellationToken cancellationToken) { var logs = _host.GetTestLoggerProvider().GetAllLogMessages(); var errors = logs.Where( p => p.Level == LogLevel.Error && // Ignore this error that the SDK logs when cancelling batch receive !p.FormattedMessage.Contains("ReceiveBatchAsync Exception: System.Threading.Tasks.TaskCanceledException")); Assert.IsEmpty(errors, string.Join(",", errors.Select(e => e.FormattedMessage))); var client = new ServiceBusAdministrationClient(ServiceBusTestEnvironment.Instance.ServiceBusConnectionString); // wait for a few seconds to allow updated counts to propagate await Task.Delay(TimeSpan.FromSeconds(2)); QueueRuntimeProperties properties = await client.GetQueueRuntimePropertiesAsync(WebJobsServiceBusTestBase._firstQueueScope.QueueName, CancellationToken.None); Assert.AreEqual(0, properties.TotalMessageCount); }
public static async Task ReportNumberOfMessages(string connectionString, string destination) { var client = new ServiceBusAdministrationClient(connectionString); QueueRuntimeProperties info = await client.GetQueueRuntimePropertiesAsync(destination); long activeMessageCount = info.ActiveMessageCount; long deadLetterMessageCount = info.DeadLetterMessageCount; long transferDeadLetterMessageCount = info.TransferDeadLetterMessageCount; string destinationDeadLetterPath = EntityNameHelper.FormatDeadLetterPath(destination); string destinationTransferDeadLetterPath = EntityNameHelper.FormatTransferDeadLetterPath(destination); Console.WriteLine($"#'{activeMessageCount}' messages in '{destination}'"); Console.WriteLine( $"#'{deadLetterMessageCount}' messages in '{destinationDeadLetterPath}'"); Console.WriteLine( $"#'{transferDeadLetterMessageCount}' messages in '{destinationTransferDeadLetterPath}'"); }
public async Task GetQueueRuntimeInfo() { var queueName = nameof(GetQueueRuntimeInfo).ToLower() + Recording.Random.NewGuid().ToString("D").Substring(0, 8); var mgmtClient = CreateClient(); await using var sbClient = new ServiceBusClient(TestEnvironment.ServiceBusConnectionString); QueueProperties queue = await mgmtClient.CreateQueueAsync(queueName); queue = await mgmtClient.GetQueueAsync(queueName); // Changing Last Updated Time queue.AutoDeleteOnIdle = TimeSpan.FromMinutes(100); QueueProperties updatedQueue = await mgmtClient.UpdateQueueAsync(queue); // Populating 1 active message, 1 dead letter message and 1 scheduled message // Changing Last Accessed Time ServiceBusSender sender = sbClient.CreateSender(queueName); 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(queueName); ServiceBusReceivedMessage msg = await receiver.ReceiveMessageAsync(); await receiver.DeadLetterMessageAsync(msg.LockToken); List <QueueRuntimeProperties> runtimeInfoList = new List <QueueRuntimeProperties>(); await foreach (QueueRuntimeProperties queueRuntimeInfo in mgmtClient.GetQueuesRuntimePropertiesAsync()) { runtimeInfoList.Add(queueRuntimeInfo); } runtimeInfoList = runtimeInfoList.Where(e => e.Name.StartsWith(nameof(GetQueueRuntimeInfo).ToLower())).ToList(); Assert.True(runtimeInfoList.Count == 1, $"Expected 1 queue but {runtimeInfoList.Count} queues returned"); QueueRuntimeProperties runtimeInfo = runtimeInfoList.First(); Assert.NotNull(runtimeInfo); Assert.AreEqual(queueName, runtimeInfo.Name); Assert.True(runtimeInfo.CreatedAt < runtimeInfo.UpdatedAt); Assert.True(runtimeInfo.UpdatedAt < runtimeInfo.AccessedAt); Assert.AreEqual(1, runtimeInfo.ActiveMessageCount); Assert.AreEqual(1, runtimeInfo.DeadLetterMessageCount); Assert.AreEqual(1, runtimeInfo.ScheduledMessageCount); Assert.AreEqual(3, runtimeInfo.TotalMessageCount); Assert.True(runtimeInfo.SizeInBytes > 0); QueueRuntimeProperties singleRuntimeInfo = await mgmtClient.GetQueueRuntimePropertiesAsync(runtimeInfo.Name); Assert.AreEqual(runtimeInfo.AccessedAt, singleRuntimeInfo.AccessedAt); Assert.AreEqual(runtimeInfo.CreatedAt, singleRuntimeInfo.CreatedAt); Assert.AreEqual(runtimeInfo.UpdatedAt, singleRuntimeInfo.UpdatedAt); Assert.AreEqual(runtimeInfo.TotalMessageCount, singleRuntimeInfo.TotalMessageCount); Assert.AreEqual(runtimeInfo.ActiveMessageCount, singleRuntimeInfo.ActiveMessageCount); Assert.AreEqual(runtimeInfo.DeadLetterMessageCount, singleRuntimeInfo.DeadLetterMessageCount); Assert.AreEqual(runtimeInfo.ScheduledMessageCount, singleRuntimeInfo.ScheduledMessageCount); Assert.AreEqual(runtimeInfo.SizeInBytes, singleRuntimeInfo.SizeInBytes); await mgmtClient.DeleteQueueAsync(queueName); }
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(); }