public async Task ForwardingEntity() { // queueName--Fwd to--> destinationName--fwd dlq to-- > dqlDestinationName var queueName = Guid.NewGuid().ToString("D").Substring(0, 8); var destinationName = Guid.NewGuid().ToString("D").Substring(0, 8); var dlqDestinationName = Guid.NewGuid().ToString("D").Substring(0, 8); var mgmtClient = new ServiceBusManagementClient(TestEnvironment.ServiceBusConnectionString); await mgmtClient.CreateQueueAsync(dlqDestinationName); await mgmtClient.CreateQueueAsync( new CreateQueueOptions(destinationName) { ForwardDeadLetteredMessagesTo = dlqDestinationName }); await mgmtClient.CreateQueueAsync( new CreateQueueOptions(queueName) { ForwardTo = destinationName }); await using var sbClient = new ServiceBusClient(TestEnvironment.ServiceBusConnectionString); ServiceBusSender sender = sbClient.CreateSender(queueName); await sender.SendMessageAsync(new ServiceBusMessage() { MessageId = "mid" }); ServiceBusReceiver receiver = sbClient.CreateReceiver(destinationName); ServiceBusReceivedMessage msg = await receiver.ReceiveMessageAsync(); Assert.NotNull(msg); Assert.AreEqual("mid", msg.MessageId); await receiver.DeadLetterMessageAsync(msg.LockToken); receiver = sbClient.CreateReceiver(dlqDestinationName); msg = await receiver.ReceiveMessageAsync(); Assert.NotNull(msg); Assert.AreEqual("mid", msg.MessageId); await receiver.CompleteMessageAsync(msg.LockToken); await mgmtClient.DeleteQueueAsync(queueName); await mgmtClient.DeleteQueueAsync(destinationName); await mgmtClient.DeleteQueueAsync(dlqDestinationName); }
public async Task GetUpdateDeleteQueue() { string queueName = Guid.NewGuid().ToString("D").Substring(0, 8); string connectionString = TestEnvironment.ServiceBusConnectionString; var client = new ServiceBusManagementClient(connectionString); var qd = new CreateQueueOptions(queueName); await client.CreateQueueAsync(qd); #region Snippet:GetQueue QueueProperties queue = await client.GetQueueAsync(queueName); #endregion #region Snippet:UpdateQueue queue.LockDuration = TimeSpan.FromSeconds(60); QueueProperties updatedQueue = await client.UpdateQueueAsync(queue); #endregion Assert.AreEqual(TimeSpan.FromSeconds(60), updatedQueue.LockDuration); #region Snippet:DeleteQueue await client.DeleteQueueAsync(queueName); #endregion Assert.That( async() => await client.GetQueueAsync(queueName), Throws.InstanceOf <ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusFailureReason.MessagingEntityNotFound)); }
public async Task ThrowsIfEntityAlreadyExists() { var client = new ServiceBusManagementClient(TestEnvironment.ServiceBusConnectionString); var queueName = Guid.NewGuid().ToString("D").Substring(0, 8); var topicName = Guid.NewGuid().ToString("D").Substring(0, 8); var subscriptionName = Guid.NewGuid().ToString("D").Substring(0, 8); await client.CreateQueueAsync(queueName); await client.CreateTopicAsync(topicName); await client.CreateSubscriptionAsync(topicName, subscriptionName); Assert.That( async() => await client.CreateQueueAsync(queueName), Throws.InstanceOf <ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusException.FailureReason.MessagingEntityAlreadyExists)); Assert.That( async() => await client.CreateTopicAsync(topicName), Throws.InstanceOf <ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusException.FailureReason.MessagingEntityAlreadyExists)); Assert.That( async() => await client.CreateSubscriptionAsync(topicName, subscriptionName), Throws.InstanceOf <ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusException.FailureReason.MessagingEntityAlreadyExists)); await client.DeleteQueueAsync(queueName); await client.DeleteTopicAsync(topicName); }
public async Task AuthenticateWithAAD() { var queueName = Guid.NewGuid().ToString("D").Substring(0, 8); var topicName = Guid.NewGuid().ToString("D").Substring(0, 8); var client = new ServiceBusManagementClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential); var queueOptions = new CreateQueueOptions(queueName); QueueProperties createdQueue = await client.CreateQueueAsync(queueOptions); Assert.AreEqual(queueOptions, new CreateQueueOptions(createdQueue)); var topicOptions = new CreateTopicOptions(topicName); TopicProperties createdTopic = await client.CreateTopicAsync(topicOptions); Assert.AreEqual(topicOptions, new CreateTopicOptions(createdTopic)); await client.DeleteQueueAsync(queueName); await client.DeleteTopicAsync(topicName); }
public async Task AuthenticateWithAAD() { var queueName = Guid.NewGuid().ToString("D").Substring(0, 8); var topicName = Guid.NewGuid().ToString("D").Substring(0, 8); var client = new ServiceBusManagementClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential); QueueDescription queueDescription = new QueueDescription(queueName); QueueDescription createdQueue = await client.CreateQueueAsync(queueDescription); Assert.AreEqual(queueDescription, createdQueue); TopicDescription topicDescription = new TopicDescription(topicName); TopicDescription createdTopic = await client.CreateTopicAsync(topicDescription); Assert.AreEqual(topicDescription, createdTopic); await client.DeleteQueueAsync(queueName); await client.DeleteTopicAsync(topicName); }
public async Task ThrowsIfEntityDoesNotExist() { var client = new ServiceBusManagementClient(TestEnvironment.ServiceBusConnectionString); Assert.That( async() => await client.GetQueueAsync("NonExistingPath"), Throws.InstanceOf <ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusException.FailureReason.MessagingEntityNotFound)); Assert.That( async() => await client.GetQueueAsync("NonExistingTopic"), Throws.InstanceOf <ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusException.FailureReason.MessagingEntityNotFound)); Assert.That( async() => await client.GetSubscriptionAsync("NonExistingTopic", "NonExistingPath"), Throws.InstanceOf <ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusException.FailureReason.MessagingEntityNotFound)); Assert.That( async() => await client.UpdateQueueAsync(new QueueProperties("NonExistingPath")), Throws.InstanceOf <ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusException.FailureReason.MessagingEntityNotFound)); Assert.That( async() => await client.UpdateTopicAsync(new TopicProperties("NonExistingPath")), Throws.InstanceOf <ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusException.FailureReason.MessagingEntityNotFound)); Assert.That( async() => await client.UpdateSubscriptionAsync(new SubscriptionProperties("NonExistingTopic", "NonExistingPath")), Throws.InstanceOf <ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusException.FailureReason.MessagingEntityNotFound)); Assert.That( async() => await client.DeleteQueueAsync("NonExistingPath"), Throws.InstanceOf <ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusException.FailureReason.MessagingEntityNotFound)); Assert.That( async() => await client.DeleteTopicAsync("NonExistingPath"), Throws.InstanceOf <ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusException.FailureReason.MessagingEntityNotFound)); Assert.That( async() => await client.DeleteSubscriptionAsync("NonExistingTopic", "NonExistingPath"), Throws.InstanceOf <ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusException.FailureReason.MessagingEntityNotFound)); var queueName = Guid.NewGuid().ToString("D").Substring(0, 8); var topicName = Guid.NewGuid().ToString("D").Substring(0, 8); await client.CreateQueueAsync(queueName); await client.CreateTopicAsync(topicName); Assert.That( async() => await client.GetQueueAsync(topicName), Throws.InstanceOf <ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusException.FailureReason.MessagingEntityNotFound)); Assert.That( async() => await client.GetTopicAsync(queueName), Throws.InstanceOf <ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusException.FailureReason.MessagingEntityNotFound)); await client.DeleteQueueAsync(queueName); await client.DeleteTopicAsync(topicName); }
public async Task GetQueueRuntimeInfo() { var queueName = nameof(GetQueueRuntimeInfo).ToLower() + Guid.NewGuid().ToString("D").Substring(0, 8); var mgmtClient = new ServiceBusManagementClient(TestEnvironment.ServiceBusConnectionString); 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); }
public async Task BasicQueueCrudOperations() { var queueName = nameof(BasicQueueCrudOperations).ToLower() + Guid.NewGuid().ToString("D").Substring(0, 8); var client = new ServiceBusManagementClient(TestEnvironment.ServiceBusConnectionString); var queueOptions = new CreateQueueOptions(queueName) { AutoDeleteOnIdle = TimeSpan.FromHours(1), DefaultMessageTimeToLive = TimeSpan.FromDays(2), DuplicateDetectionHistoryTimeWindow = TimeSpan.FromMinutes(1), EnableBatchedOperations = false, DeadLetteringOnMessageExpiration = true, EnablePartitioning = false, ForwardDeadLetteredMessagesTo = null, ForwardTo = null, LockDuration = TimeSpan.FromSeconds(45), MaxDeliveryCount = 8, MaxSizeInMegabytes = 2048, RequiresDuplicateDetection = true, RequiresSession = false, UserMetadata = nameof(BasicQueueCrudOperations), Status = EntityStatus.Disabled }; queueOptions.AuthorizationRules.Add(new SharedAccessAuthorizationRule( "allClaims", new[] { AccessRights.Manage, AccessRights.Send, AccessRights.Listen })); QueueProperties createdQueue = await client.CreateQueueAsync(queueOptions); Assert.AreEqual(queueOptions, new CreateQueueOptions(createdQueue)); QueueProperties getQueue = await client.GetQueueAsync(queueOptions.Name); Assert.AreEqual(createdQueue, getQueue); getQueue.EnableBatchedOperations = false; getQueue.MaxDeliveryCount = 9; getQueue.AuthorizationRules.Clear(); getQueue.AuthorizationRules.Add(new SharedAccessAuthorizationRule( "noManage", new[] { AccessRights.Send, AccessRights.Listen })); getQueue.EnableBatchedOperations = true; getQueue.Status = EntityStatus.Disabled; getQueue.AutoDeleteOnIdle = TimeSpan.FromMinutes(6); getQueue.MaxSizeInMegabytes = 1024; QueueProperties updatedQueue = await client.UpdateQueueAsync(getQueue); Assert.AreEqual(getQueue, updatedQueue); bool isExists = await client.QueueExistsAsync(queueName); Assert.True(isExists); List <QueueProperties> queueList = new List <QueueProperties>(); await foreach (QueueProperties queue in client.GetQueuesAsync()) { queueList.Add(queue); } queueList = queueList.Where(e => e.Name.StartsWith(nameof(BasicQueueCrudOperations).ToLower())).ToList(); Assert.True(queueList.Count == 1, $"Expected 1 queue but {queueList.Count} queues returned"); Assert.AreEqual(queueList.First().Name, queueName); await client.DeleteQueueAsync(updatedQueue.Name); Assert.That( async() => await client.GetQueueAsync(queueOptions.Name), Throws.InstanceOf <ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusException.FailureReason.MessagingEntityNotFound)); isExists = await client.QueueExistsAsync(queueName); Assert.False(isExists); }