public void Save()
 {
     if (EntityType == ServiceBusEntityType.Queue)
     {
         _manager.CreateQueue(Path, Users);
     }
     else
     {
         _manager.CreateTopic(Path, Users);
     }
 }
Example #2
0
        public async Task RunTest()
        {
            var topic            = "competing" + (new Random().Next()).ToString();
            var subscriptionName = "subscriptionTo" + topic;

            await mgt.CreateTopic(topic);


            await mgt.CreateSubscription(topic, subscriptionName);


            var sender = new TopicClient(config.ConnectionString, topic);

            Microsoft.Azure.ServiceBus.SubscriptionClient receiver1 = new SubscriptionClient(config.ConnectionString, topic, subscriptionName, ReceiveMode.ReceiveAndDelete);
            receiver1.RegisterMessageHandler((message, ct) =>
            {
                Console.WriteLine("Receved On Receiver 1");
                System.Threading.Thread.Sleep(500);
                return(Task.CompletedTask);
            }, new MessageHandlerOptions((e) => Task.CompletedTask));


            Microsoft.Azure.ServiceBus.SubscriptionClient receiver2 = new SubscriptionClient(config.ConnectionString, topic, subscriptionName, ReceiveMode.ReceiveAndDelete);
            receiver2.RegisterMessageHandler((message, ct) =>
            {
                Console.WriteLine("Receved On Receiver 2");
                System.Threading.Thread.Sleep(500);
                return(Task.CompletedTask);
            }, new MessageHandlerOptions((e) => Task.CompletedTask));


            for (int x = 0; x < 10; x++)
            {
                await sender.SendAsync(new Message { Body = new byte[0], CorrelationId = Guid.NewGuid().ToString() });
            }
        }
Example #3
0
        private async Task CopyTopics(ProgressDialogController controller)
        {
            var topicsToUpdate = _fromManager.Topics.Where(a => _toManager.Topics.Select(b => b.Path).Contains(a.Path)).ToList();

            foreach (var topic in topicsToUpdate)
            {
                controller.SetMessage(string.Format("Updating: {0}", topic.Path));
                await Task.Run(() =>
                {
                    _toManager.UpdateTopic(topic);

                    // Add missing subscription
                    foreach (var subscription in _fromManager.GetSubscriptions(topic).Where(a => !_toManager.GetSubscriptions(topic).Select(b => b.Name).Contains(a.Name)))
                    {
                        _toManager.AddSubscription(subscription);
                    }
                });
            }

            var topicsToAdd = _fromManager.Topics.Except(_toManager.Topics, new LambdaComparer <TopicDescription>((a, b) => a.Path == b.Path, a => 1)).ToList();

            foreach (var topic in topicsToAdd)
            {
                controller.SetMessage(string.Format("Adding: {0}", topic.Path));
                await Task.Run(() =>
                {
                    _toManager.CreateTopic(topic);

                    // Add missing subscription
                    foreach (var subscription in _fromManager.GetSubscriptions(topic))
                    {
                        _toManager.AddSubscription(subscription);
                    }
                });
            }
        }