Exemple #1
0
 public async Task Create()
 {
     #region Snippet:Managing_ServiceBusTopics_CreateTopic
     string          topicName       = "myTopic";
     ServiceBusTopic serviceBusTopic = (await serviceBusTopicCollection.CreateOrUpdateAsync(WaitUntil.Completed, topicName, new ServiceBusTopicData())).Value;
     #endregion
 }
Exemple #2
0
        public async Task Get()
        {
            #region Snippet:Managing_ServiceBusTopics_GetTopic
            ServiceBusTopic serviceBusTopic = await serviceBusTopicCollection.GetAsync("myTopic");

            #endregion
        }
Exemple #3
0
        public async Task CreateDeleteTopic()
        {
            IgnoreTestInLiveMode();
            //create topic
            string          topicName = Recording.GenerateAssetName("topic");
            ServiceBusTopic topic     = (await _topicCollection.CreateOrUpdateAsync(topicName, new ServiceBusTopicData())).Value;

            Assert.NotNull(topic);
            Assert.AreEqual(topic.Id.Name, topicName);

            //validate if created successfully
            topic = await _topicCollection.GetIfExistsAsync(topicName);

            Assert.NotNull(topic);
            Assert.IsTrue(await _topicCollection.CheckIfExistsAsync(topicName));

            //delete topic
            await topic.DeleteAsync();

            //validate
            topic = await _topicCollection.GetIfExistsAsync(topicName);

            Assert.Null(topic);
            Assert.IsFalse(await _topicCollection.CheckIfExistsAsync(topicName));
        }
 public ServiceBusTopicPostman(string topic, string need, string messageBody, IServiceBusPostman nextPostman) :
     this(ServiceBusTopic.Client(topic), messageBody.AsServiceBusMessage(new []
 {
     new UserProperty(new NeedUserPropertyName(), need)
 }), nextPostman)
 {
 }
Exemple #5
0
        public async Task Delete()
        {
            #region Snippet:Managing_ServiceBusTopics_DeleteTopic
            ServiceBusTopic serviceBusTopic = await serviceBusTopicCollection.GetAsync("myTopic");

            await serviceBusTopic.DeleteAsync(WaitUntil.Completed);

            #endregion
        }
Exemple #6
0
        public async Task TopicCreateGetUpdateDeleteAuthorizationRule()
        {
            IgnoreTestInLiveMode();
            //create topic
            string          topicName = Recording.GenerateAssetName("topic");
            ServiceBusTopic topic     = (await _topicCollection.CreateOrUpdateAsync(topicName, new ServiceBusTopicData())).Value;

            //create an authorization rule
            string ruleName = Recording.GenerateAssetName("authorizationrule");
            NamespaceTopicAuthorizationRuleCollection ruleCollection = topic.GetNamespaceTopicAuthorizationRules();
            ServiceBusAuthorizationRuleData           parameter      = new ServiceBusAuthorizationRuleData()
            {
                Rights = { AccessRights.Listen, AccessRights.Send }
            };
            NamespaceTopicAuthorizationRule authorizationRule = (await ruleCollection.CreateOrUpdateAsync(ruleName, parameter)).Value;

            Assert.NotNull(authorizationRule);
            Assert.AreEqual(authorizationRule.Data.Rights.Count, parameter.Rights.Count);

            //get authorization rule
            authorizationRule = await ruleCollection.GetAsync(ruleName);

            Assert.AreEqual(authorizationRule.Id.Name, ruleName);
            Assert.NotNull(authorizationRule);
            Assert.AreEqual(authorizationRule.Data.Rights.Count, parameter.Rights.Count);

            //get all authorization rules
            List <NamespaceTopicAuthorizationRule> rules = await ruleCollection.GetAllAsync().ToEnumerableAsync();

            //validate
            Assert.True(rules.Count == 1);
            bool isContainAuthorizationRuleName = false;

            foreach (NamespaceTopicAuthorizationRule rule in rules)
            {
                if (rule.Id.Name == ruleName)
                {
                    isContainAuthorizationRuleName = true;
                }
            }
            Assert.True(isContainAuthorizationRuleName);

            //update authorization rule
            parameter.Rights.Add(AccessRights.Manage);
            authorizationRule = (await ruleCollection.CreateOrUpdateAsync(ruleName, parameter)).Value;
            Assert.NotNull(authorizationRule);
            Assert.AreEqual(authorizationRule.Data.Rights.Count, parameter.Rights.Count);

            //delete authorization rule
            await authorizationRule.DeleteAsync();

            //validate if deleted
            Assert.IsFalse(await ruleCollection.CheckIfExistsAsync(ruleName));
            rules = await ruleCollection.GetAllAsync().ToEnumerableAsync();

            Assert.True(rules.Count == 0);
        }
        public void GivenTopic_WhenAskingForClient_ThenItReturnsCorrectClient()
        {
            // arrange
            // act
            const string expected    = "topic";
            ITopicClient topicClient = ServiceBusTopic.Client(expected);

            // assert
            topicClient.TopicName.Should().Be(expected);
        }
        public void GivenTopic_WhenAskingForClientTwice_ThenItReturnsTheSameObject()
        {
            // arrange
            // act
            const string topic              = "topic";
            ITopicClient topicClient        = ServiceBusTopic.Client(topic);
            ITopicClient anotherTopicClient = ServiceBusTopic.Client(topic);

            // assert
            topicClient.Should().Be(anotherTopicClient);
        }
        private string GetName(ServiceBusTopic topic)
        {
            switch (topic)
            {
            case ServiceBusTopic.ResetTranslationsCache:
                return("resettranslationscache");

            default:
                throw new NotImplementedException("This topic does not have a defined name yet.");
            }
        }
        public void GivenTopics_WhenAskingForDifferentTopicClients_ThenItReturnDistinctObjects()
        {
            // arrange
            // act
            const string topic1       = "topic1";
            const string topic2       = "topic2";
            ITopicClient topicClient1 = ServiceBusTopic.Client(topic1);
            ITopicClient topicClient2 = ServiceBusTopic.Client(topic2);

            // assert
            topicClient1.Should().NotBe(topicClient2);
        }
        public async Task UpdateTopic()
        {
            IgnoreTestInLiveMode();
            //create topic
            string topicName = Recording.GenerateAssetName("topic");
            ServiceBusTopic topic = (await _topicCollection.CreateOrUpdateAsync(true, topicName, new ServiceBusTopicData())).Value;
            Assert.NotNull(topic);
            Assert.AreEqual(topic.Id.Name, topicName);

            //update topic
            topic.Data.MaxMessageSizeInKilobytes = 13312;
            topic = (await _topicCollection.CreateOrUpdateAsync(true, topicName, topic.Data)).Value;
            Assert.AreEqual(topic.Data.MaxMessageSizeInKilobytes, 13312);
        }
Exemple #12
0
        public async Task GetIfExist()
        {
            #region Snippet:Managing_ServiceBusTopics_GetTopicIfExists
            ServiceBusTopic serviceBusTopic = await serviceBusTopicCollection.GetIfExistsAsync("foo");

            if (serviceBusTopic != null)
            {
                Console.WriteLine("topic 'foo' exists");
            }
            if (await serviceBusTopicCollection.ExistsAsync("bar"))
            {
                Console.WriteLine("topic 'bar' exists");
            }
            #endregion
        }
Exemple #13
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ServiceBusTopic = await _context.ServiceBusTopic
                              .Include(s => s.NamespaceNavigation).FirstOrDefaultAsync(m => m.TopicId == id);

            if (ServiceBusTopic == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Exemple #14
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ServiceBusTopic = await _context.ServiceBusTopic.FindAsync(id);

            if (ServiceBusTopic != null)
            {
                _context.ServiceBusTopic.Remove(ServiceBusTopic);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemple #15
0
        public async Task TopicAuthorizationRuleRegenerateKey()
        {
            IgnoreTestInLiveMode();
            //create topic
            string          topicName = Recording.GenerateAssetName("topic");
            ServiceBusTopic topic     = (await _topicCollection.CreateOrUpdateAsync(topicName, new ServiceBusTopicData())).Value;
            NamespaceTopicAuthorizationRuleCollection ruleCollection = topic.GetNamespaceTopicAuthorizationRules();

            //create authorization rule
            string ruleName = Recording.GenerateAssetName("authorizationrule");
            ServiceBusAuthorizationRuleData parameter = new ServiceBusAuthorizationRuleData()
            {
                Rights = { AccessRights.Listen, AccessRights.Send }
            };
            NamespaceTopicAuthorizationRule authorizationRule = (await ruleCollection.CreateOrUpdateAsync(ruleName, parameter)).Value;

            Assert.NotNull(authorizationRule);
            Assert.AreEqual(authorizationRule.Data.Rights.Count, parameter.Rights.Count);

            AccessKeys keys1 = await authorizationRule.GetKeysAsync();

            Assert.NotNull(keys1);
            Assert.NotNull(keys1.PrimaryConnectionString);
            Assert.NotNull(keys1.SecondaryConnectionString);

            AccessKeys keys2 = await authorizationRule.RegenerateKeysAsync(new RegenerateAccessKeyOptions(KeyType.PrimaryKey));

            //the recordings are sanitized therefore cannot be compared
            if (Mode != RecordedTestMode.Playback)
            {
                Assert.AreNotEqual(keys1.PrimaryKey, keys2.PrimaryKey);
                Assert.AreEqual(keys1.SecondaryKey, keys2.SecondaryKey);
            }

            AccessKeys keys3 = await authorizationRule.RegenerateKeysAsync(new RegenerateAccessKeyOptions(KeyType.SecondaryKey));

            if (Mode != RecordedTestMode.Playback)
            {
                Assert.AreEqual(keys2.PrimaryKey, keys3.PrimaryKey);
                Assert.AreNotEqual(keys2.SecondaryKey, keys3.SecondaryKey);
            }
        }
Exemple #16
0
        async Task MainTopicAsync()
        {
            Console.WriteLine("Topic Program Started");
            try
            {
                serviceBusTopic.Subscription1 += OnMessageReceived;
                Console.WriteLine("Sending message to service bus");
                await serviceBusTopic.SendMessageAsync("Sample topic message");

                Console.WriteLine("Message sent successfully");
                var serviceBusClient = new ServiceBusTopic(AppSettings.ServiceBusConnectionString, AppSettings.ServiceBusTopicName); //,
                                                                                                                                     //await serviceBusTopic.SendMessageAsync("Sample topic message");
                await serviceBusClient.SendMessageAsync($"{AppSettings.ServiceBusTopicSubscriptionName}1", "Sample topic message");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error occurred" + ex.Message);
            }

            Console.WriteLine("Press any key to proceed");
            Console.ReadKey();
        }
Exemple #17
0
        public async Task <IList <ServiceBusTopic> > GetTopics(string connectionString)
        {
            IList <ServiceBusTopic> topics = new List <ServiceBusTopic>();
            var client    = new ManagementClient(connectionString);
            var busTopics = await client.GetTopicsAsync();

            await client.CloseAsync();

            await Task.WhenAll(busTopics.Select(async t =>
            {
                var topicName     = t.Path;
                var subscriptions = await GetSubscriptions(connectionString, topicName);

                var newTopic = new ServiceBusTopic
                {
                    Name = topicName
                };

                newTopic.AddSubscriptions(subscriptions.ToArray());
                topics.Add(newTopic);
            }));

            return(topics);
        }
 /// <summary>
 /// Creates a new topic. Once created, this topic resource manifest is
 /// immutable. This operation is not idempotent. Repeating the create
 /// call, after a topic with same name has been created successfully,
 /// will result in a 409 Conflict error message.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/hh780728.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.ServiceBus.ITopicOperations.
 /// </param>
 /// <param name='namespaceName'>
 /// The namespace name.
 /// </param>
 /// <param name='topic'>
 /// The Service Bus topic.
 /// </param>
 /// <returns>
 /// A response to a request for a particular topic.
 /// </returns>
 public static ServiceBusTopicResponse Create(this ITopicOperations operations, string namespaceName, ServiceBusTopic topic)
 {
     try
     {
         return(operations.CreateAsync(namespaceName, topic).Result);
     }
     catch (AggregateException ex)
     {
         if (ex.InnerExceptions.Count > 1)
         {
             throw;
         }
         else
         {
             throw ex.InnerException;
         }
     }
 }
Exemple #19
0
 public BenefitController(ServiceBusTopic serviceBusTopic, EventHubSender eventHubSender)
 {
     _serviceBusTopic = serviceBusTopic;
     _eventHubSender  = eventHubSender;
 }
 /// <summary>
 /// Creates a new topic. Once created, this topic resource manifest is
 /// immutable. This operation is not idempotent. Repeating the create
 /// call, after a topic with same name has been created successfully,
 /// will result in a 409 Conflict error message.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/hh780728.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.ServiceBus.ITopicOperations.
 /// </param>
 /// <param name='namespaceName'>
 /// Required. The namespace name.
 /// </param>
 /// <param name='topic'>
 /// Required. The Service Bus topic.
 /// </param>
 /// <returns>
 /// A response to a request for a particular topic.
 /// </returns>
 public static Task <ServiceBusTopicResponse> CreateAsync(this ITopicOperations operations, string namespaceName, ServiceBusTopic topic)
 {
     return(operations.CreateAsync(namespaceName, topic, CancellationToken.None));
 }
Exemple #21
0
 public InternalMessagesQueue(string connectionString, string serverInstanceName)
 {
     _serviceBus = new ServiceBusTopic();
     _serviceBus.Initialize(QueueName, "TranscendenceChatWorkerRole", string.Format("To = '{0}'", serverInstanceName), connectionString);
     _serviceBus.MessageReceived += OnMessageReceived;
 }
Exemple #22
0
        public async Task CreateGetUpdateDeleteRule()
        {
            IgnoreTestInLiveMode();

            const string strSqlExp = "myproperty=test";

            //create namespace
            ResourceGroup resourceGroup = await CreateResourceGroupAsync();

            string namespaceName = await CreateValidNamespaceName("testnamespacemgmt");

            ServiceBusNamespaceCollection namespaceCollection = resourceGroup.GetServiceBusNamespaces();
            ServiceBusNamespace           serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new ServiceBusNamespaceData(DefaultLocation))).Value;

            //create a topic
            ServiceBusTopicCollection topicCollection = serviceBusNamespace.GetServiceBusTopics();
            string          topicName = Recording.GenerateAssetName("topic");
            ServiceBusTopic topic     = (await topicCollection.CreateOrUpdateAsync(WaitUntil.Completed, topicName, new ServiceBusTopicData())).Value;

            Assert.NotNull(topic);
            Assert.AreEqual(topic.Id.Name, topicName);

            //create a subscription
            ServiceBusSubscriptionCollection serviceBusSubscriptionCollection = topic.GetServiceBusSubscriptions();
            string subscriptionName = Recording.GenerateAssetName("subscription");
            ServiceBusSubscriptionData parameters             = new ServiceBusSubscriptionData();
            ServiceBusSubscription     serviceBusSubscription = (await serviceBusSubscriptionCollection.CreateOrUpdateAsync(WaitUntil.Completed, subscriptionName, parameters)).Value;

            Assert.NotNull(serviceBusSubscription);
            Assert.AreEqual(serviceBusSubscription.Id.Name, subscriptionName);

            //create rule with no filters
            string ruleName1 = Recording.GenerateAssetName("rule");
            ServiceBusRuleCollection ruleCollection = serviceBusSubscription.GetServiceBusRules();
            ServiceBusRule           rule1          = (await ruleCollection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName1, new ServiceBusRuleData())).Value;

            Assert.NotNull(rule1);
            Assert.AreEqual(rule1.Id.Name, ruleName1);

            //create rule with correlation filter
            string         ruleName2 = Recording.GenerateAssetName("rule");
            ServiceBusRule rule2     = (await ruleCollection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName2, new ServiceBusRuleData()
            {
                FilterType = FilterType.CorrelationFilter
            })).Value;

            Assert.NotNull(rule2);
            Assert.AreEqual(rule2.Id.Name, ruleName2);

            //get created rules
            rule1 = await ruleCollection.GetAsync(ruleName1);

            Assert.NotNull(rule1);
            Assert.AreEqual(rule1.Id.Name, ruleName1);

            //get all rules
            List <ServiceBusRule> rules = await ruleCollection.GetAllAsync().ToEnumerableAsync();

            Assert.AreEqual(2, rules.Count);

            //update rule with sql filter and action
            ServiceBusRuleData updateParameters = new ServiceBusRuleData()
            {
                Action = new SqlRuleAction()
                {
                    RequiresPreprocessing = true,
                    SqlExpression         = "SET " + strSqlExp,
                },
                SqlFilter = new SqlFilter()
                {
                    SqlExpression = strSqlExp
                },
                FilterType        = FilterType.SqlFilter,
                CorrelationFilter = new CorrelationFilter()
            };

            rule1 = (await ruleCollection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName1, updateParameters)).Value;

            await rule1.DeleteAsync(WaitUntil.Completed);

            await rule2.DeleteAsync(WaitUntil.Completed);
        }
 /// <summary>
 /// Creates a new topic. Once created, this topic resource manifest is
 /// immutable. This operation is not idempotent. Repeating the create
 /// call, after a topic with same name has been created successfully,
 /// will result in a 409 Conflict error message.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/hh780728.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.ServiceBus.ITopicOperations.
 /// </param>
 /// <param name='namespaceName'>
 /// Required. The namespace name.
 /// </param>
 /// <param name='topic'>
 /// Required. The Service Bus topic.
 /// </param>
 /// <returns>
 /// A response to a request for a particular topic.
 /// </returns>
 public static ServiceBusTopicResponse Create(this ITopicOperations operations, string namespaceName, ServiceBusTopic topic)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((ITopicOperations)s).CreateAsync(namespaceName, topic);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Exemple #24
0
 public ResetTranslationsCacheMessage(ServiceBusTopic topic, List <string> cacheNames)
 {
     Topic      = topic;
     CacheNames = cacheNames;
 }
Exemple #25
0
 public ResetTranslationsCacheSubsriptionRequirements(ServiceBusTopic topic, string context, IDistributedCache distributedCache)
 {
     Topic            = topic;
     Context          = context;
     DistributedCache = distributedCache;
 }
Exemple #26
0
 public ServiceBusProgram()
 {
     serviceBusQueue = new ServiceBusQueue(AppSettings.ServiceBusConnectionString, AppSettings.ServiceBusQueueName);
     serviceBusTopic = new ServiceBusTopic(AppSettings.ServiceBusConnectionString, AppSettings.ServiceBusTopicName, AppSettings.ServiceBusTopicSubscriptionName);
 }
Exemple #27
0
        public async Task CreateGetUpdateDeleteSubscription()
        {
            IgnoreTestInLiveMode();
            //create namespace
            ResourceGroup resourceGroup = await CreateResourceGroupAsync();
            string namespaceName = await CreateValidNamespaceName("testnamespacemgmt");
            ServiceBusNamespaceCollection namespaceCollection = resourceGroup.GetServiceBusNamespaces();
            ServiceBusNamespace serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new ServiceBusNamespaceData(DefaultLocation))).Value;

            //create a topic
            ServiceBusTopicCollection topicCollection = serviceBusNamespace.GetServiceBusTopics();
            string topicName = Recording.GenerateAssetName("topic");
            ServiceBusTopic topic = (await topicCollection.CreateOrUpdateAsync(WaitUntil.Completed, topicName, new ServiceBusTopicData())).Value;
            Assert.NotNull(topic);
            Assert.AreEqual(topic.Id.Name, topicName);

            //create a subscription
            ServiceBusSubscriptionCollection serviceBusSubscriptionCollection = topic.GetServiceBusSubscriptions();
            string subscriptionName = Recording.GenerateAssetName("subscription");
            ServiceBusSubscriptionData parameters = new ServiceBusSubscriptionData()
            {
                EnableBatchedOperations = true,
                LockDuration = TimeSpan.Parse("00:03:00"),
                DefaultMessageTimeToLive = TimeSpan.Parse("00:05:00"),
                DeadLetteringOnMessageExpiration = true,
                MaxDeliveryCount = 14,
                Status = EntityStatus.Active,
                AutoDeleteOnIdle = TimeSpan.Parse("00:07:00"),
                DeadLetteringOnFilterEvaluationExceptions = true
            };
            ServiceBusSubscription serviceBusSubscription = (await serviceBusSubscriptionCollection.CreateOrUpdateAsync(WaitUntil.Completed, subscriptionName, parameters)).Value;
            Assert.NotNull(serviceBusSubscription);
            Assert.AreEqual(serviceBusSubscription.Id.Name, subscriptionName);

            //get created subscription
            serviceBusSubscription = await serviceBusSubscriptionCollection.GetAsync(subscriptionName);
            Assert.NotNull(serviceBusSubscription);
            Assert.AreEqual(serviceBusSubscription.Id.Name, subscriptionName);
            Assert.AreEqual(serviceBusSubscription.Data.Status, EntityStatus.Active);

            //get all subscriptions
            List<ServiceBusSubscription> serviceBusSubscriptions = await serviceBusSubscriptionCollection.GetAllAsync().ToEnumerableAsync();
            Assert.AreEqual(serviceBusSubscriptions.Count, 1);

            //create a topic for autoforward
            string topicName1 = Recording.GenerateAssetName("topic");
            ServiceBusTopic topic1 = (await topicCollection.CreateOrUpdateAsync(WaitUntil.Completed, topicName1, new ServiceBusTopicData() { EnablePartitioning = true})).Value;
            Assert.NotNull(topic1);
            Assert.AreEqual(topic1.Id.Name, topicName1);

            //update subscription and validate
            ServiceBusSubscriptionData updateParameters = new ServiceBusSubscriptionData()
            {
                EnableBatchedOperations = true,
                DeadLetteringOnMessageExpiration = true,
                ForwardDeadLetteredMessagesTo = topicName1,
                ForwardTo = topicName1
            };
            serviceBusSubscription = (await serviceBusSubscriptionCollection.CreateOrUpdateAsync(WaitUntil.Completed, subscriptionName, updateParameters)).Value;
            Assert.NotNull(serviceBusSubscription);
            Assert.AreEqual(serviceBusSubscription.Id.Name, subscriptionName);
            Assert.AreEqual(serviceBusSubscription.Data.Status, EntityStatus.Active);
            Assert.IsTrue(serviceBusSubscription.Data.EnableBatchedOperations);
            Assert.AreEqual(serviceBusSubscription.Data.ForwardTo, topicName1);

            //delete subscription
            await serviceBusSubscription.DeleteAsync(WaitUntil.Completed);
            Assert.IsFalse(await serviceBusSubscriptionCollection.ExistsAsync(subscriptionName));
        }
 public InternalMessagesQueue(string connectionString, string serverInstanceName)
 {
     _serviceBus = new ServiceBusTopic();
     _serviceBus.Initialize(QueueName, "KinderChatWorkerRole", string.Format("To = '{0}'", serverInstanceName), connectionString);
     _serviceBus.MessageReceived += OnMessageReceived;
 }