コード例 #1
0
        public static async Task <TopicProperties> UpdateTopicAsync(TopicProperties topic, string connectionString)
        {
            var client = new ServiceBusAdministrationClient(connectionString);

            topic.UserMetadata = "other metadata";
            return(await client.UpdateTopicAsync(topic));
        }
コード例 #2
0
        public async Task GetUpdateDeleteTopicAndSubscription()
        {
            string topicName           = Guid.NewGuid().ToString("D").Substring(0, 8);
            string subscriptionName    = Guid.NewGuid().ToString("D").Substring(0, 8);
            string connectionString    = TestEnvironment.ServiceBusConnectionString;
            var    client              = new ServiceBusAdministrationClient(connectionString);
            var    topicOptions        = new CreateTopicOptions(topicName);
            var    subscriptionOptions = new CreateSubscriptionOptions(topicName, subscriptionName);
            await client.CreateTopicAsync(topicOptions);

            await client.CreateSubscriptionAsync(subscriptionOptions);

            #region Snippet:GetTopic
            TopicProperties topic = await client.GetTopicAsync(topicName);

            #endregion
            #region Snippet:GetSubscription
            SubscriptionProperties subscription = await client.GetSubscriptionAsync(topicName, subscriptionName);

            #endregion
            #region Snippet:UpdateTopic
            topic.UserMetadata = "some metadata";
            TopicProperties updatedTopic = await client.UpdateTopicAsync(topic);

            #endregion
            Assert.AreEqual("some metadata", updatedTopic.UserMetadata);

            #region Snippet:UpdateSubscription
            subscription.UserMetadata = "some metadata";
            SubscriptionProperties updatedSubscription = await client.UpdateSubscriptionAsync(subscription);

            #endregion
            Assert.AreEqual("some metadata", updatedSubscription.UserMetadata);

            // need to delete the subscription before the topic, as deleting
            // the topic would automatically delete the subscription
            #region Snippet:DeleteSubscription
            await client.DeleteSubscriptionAsync(topicName, subscriptionName);

            #endregion
            Assert.That(
                async() =>
                await client.GetSubscriptionAsync(topicName, subscriptionName),
                Throws.InstanceOf <ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusFailureReason.MessagingEntityNotFound));

            #region Snippet:DeleteTopic
            await client.DeleteTopicAsync(topicName);

            #endregion
            Assert.That(
                async() =>
                await client.GetTopicAsync(topicName),
                Throws.InstanceOf <ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusFailureReason.MessagingEntityNotFound));
        }