コード例 #1
0
        public void CreateTopic(string topicName)
        {
            if (_manager == null)
            {
                throw new TransportException(_address.Uri, "The namespace manager is not available");
            }

            if (_manager.TopicExists(topicName))
            {
                return;
            }

            var description = new TopicDescription(topicName)
            {
                DefaultMessageTimeToLive = _address.DefaultMessageTimeToLive,
                EnableBatchedOperations  = _address.EnableBatchOperations,
            };

            try
            {
                _manager.CreateTopic(description);
            }
            catch (MessagingEntityAlreadyExistsException ex)
            {
            }
        }
コード例 #2
0
        private void Form1_Load(object sender, EventArgs e)

        {
            // default is 2, for throughput optimization, lets bump it up.
            ServicePointManager.DefaultConnectionLimit = 12;

            // another optimization, saves one round trip per msg by skipping the "I have some thing for you, is that ok?" handshake
            ServicePointManager.Expect100Continue = false;

            // Create Namespace Manager and messaging factory
            Uri serviceAddress = ServiceBusEnvironment.CreateServiceUri("sb", Config.serviceNamespace, string.Empty);

            nsManager      = new NamespaceManager(serviceAddress, TokenProvider.CreateSharedSecretTokenProvider(Config.issuerName, Config.issuerSecret));
            messageFactory = MessagingFactory.Create(serviceAddress, TokenProvider.CreateSharedSecretTokenProvider(Config.issuerName, Config.issuerSecret));

            // set up the topic with batched operations, and time to live of 10 minutes. Subscriptions will not delete the message, since multiple clients are accessing the message
            // it will expire on its own after 10 minutes.
            topicDescription = new TopicDescription(topicName)
            {
                DefaultMessageTimeToLive = TimeSpan.FromMinutes(10), Path = topicName, EnableBatchedOperations = true
            };
            if (!nsManager.TopicExists(topicDescription.Path))
            {
                nsManager.CreateTopic(topicDescription);
            }

            // create client
            eventTopic = messageFactory.CreateTopicClient(topicName);
        }
コード例 #3
0
        static void CreateTopicsAndSubscriptions(NamespaceManager namespaceManager)
        {
            Console.WriteLine("\nCreating a topic and 3 subscriptions.");

            // Create a topic and 3 subscriptions.
            TopicDescription topicDescription = namespaceManager.CreateTopic(Program.TopicName);

            Console.WriteLine("Topic created.");

            // Create a subscription for all messages sent to topic.
            namespaceManager.CreateSubscription(topicDescription.Path, SubsNameAllMessages, new TrueFilter());
            Console.WriteLine("Subscription {0} added with filter definition set to TrueFilter.", Program.SubsNameAllMessages);

            // Create a subscription that'll receive all orders which have color "blue" and quantity 10.
            namespaceManager.CreateSubscription(topicDescription.Path, SubsNameColorBlueSize10Orders, new SqlFilter("color = 'blue' AND quantity = 10"));
            Console.WriteLine("Subscription {0} added with filter definition \"color = 'blue' AND quantity = 10\".", Program.SubsNameColorBlueSize10Orders);

            //var ruleDesc = new RuleDescription();
            //ruleDesc.Filter = new CorrelationFilter("high");
            //ruleDesc.Action = new SbAction();

            // Create a subscription that'll receive all high priority orders.
            namespaceManager.CreateSubscription(topicDescription.Path, SubsNameHighPriorityOrders, new CorrelationFilter("high"));
            Console.WriteLine("Subscription {0} added with correlation filter definition \"high\".", Program.SubsNameHighPriorityOrders);

            Console.WriteLine("Create completed.");
        }
コード例 #4
0
        private bool CreateTopic()
        {
            NamespaceManager namespaceManager = NamespaceManager.CreateFromConnectionString(SBconnectionString);

            try
            {
                if (namespaceManager.TopicExists(TopicName))
                {
                    return(true);
                }
                else
                {
                    TopicDescription        myTopic      = namespaceManager.CreateTopic(TopicName);
                    SubscriptionDescription subscription = namespaceManager.CreateSubscription(myTopic.Path, SubscriptionName);
                    return(true);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(false);

                throw;
            }
        }
コード例 #5
0
        private static string SendTopicMessage(string id)
        {
            //Service Bus接続文字列
            string connectionString = CloudConfigurationManager.GetSetting("ServiceBusConnectionString");
            //Topic名
            string TopicName = CloudConfigurationManager.GetSetting("CancelTopic");
            //Subscription名
            string APISubscriptionName     = CloudConfigurationManager.GetSetting("APISubscription");
            string TriggerSubscriptionName = CloudConfigurationManager.GetSetting("TriggerSubscription");
            //NamespaceManagerの生成
            NamespaceManager nsMan = NamespaceManager.CreateFromConnectionString(connectionString);

            //TopicおよびSubscriptionの存在をチェックし、存在しない場合は新規作成
            if (nsMan.TopicExists(TopicName) == false)
            {
                nsMan.CreateTopic(TopicName);
            }
            if (nsMan.SubscriptionExists(TopicName, APISubscriptionName) == false)
            {
                nsMan.CreateSubscription(TopicName, APISubscriptionName);
            }
            if (nsMan.SubscriptionExists(TopicName, TriggerSubscriptionName) == false)
            {
                nsMan.CreateSubscription(TopicName, TriggerSubscriptionName);
            }
            //Topicクライアントの作成
            TopicClient TClient = TopicClient.CreateFromConnectionString(connectionString, TopicName);

            //Topicにメッセージを送信
            TClient.Send(new BrokeredMessage(id));
            //TopicClientをClose
            TClient.Close();
            return(id);
        }
コード例 #6
0
        static void CreateTopicsAndSubscriptions(NamespaceManager namespaceManager)
        {
            Console.WriteLine("\nCreating a topic and 3 subscriptions.");

            // Create a topic and 3 subscriptions.
            TopicDescription topicDescription = namespaceManager.CreateTopic(Program.TopicName);
            Console.WriteLine("Topic created.");

            // Create a subscription for all messages sent to topic.
            namespaceManager.CreateSubscription(topicDescription.Path, SubsNameAllMessages, new TrueFilter());
            Console.WriteLine("Subscription {0} added with filter definition set to TrueFilter.", Program.SubsNameAllMessages);

            // Create a subscription that'll receive all orders which have color "blue" and quantity 10.
            namespaceManager.CreateSubscription(topicDescription.Path, SubsNameColorBlueSize10Orders, new SqlFilter("color = 'blue' AND quantity = 10"));
            Console.WriteLine("Subscription {0} added with filter definition \"color = 'blue' AND quantity = 10\".", Program.SubsNameColorBlueSize10Orders);

            //var ruleDesc = new RuleDescription();
            //ruleDesc.Filter = new CorrelationFilter("high");
            //ruleDesc.Action = new SbAction();

            // Create a subscription that'll receive all high priority orders.
            namespaceManager.CreateSubscription(topicDescription.Path, SubsNameHighPriorityOrders, new CorrelationFilter("high"));
            Console.WriteLine("Subscription {0} added with correlation filter definition \"high\".", Program.SubsNameHighPriorityOrders);

            Console.WriteLine("Create completed.");
        }
コード例 #7
0
        public void TestSubscriptionEnableDeadLetteringOnMessageExpiration()
        {
            string name      = "EnableDeadLetteringOnMessageExpiration";
            string topicName = "EnableDeadLetteringOnMessageExpiration";

            NamespaceManager ns = NamespaceManager.CreateFromConnectionString(serviceBusConnectionString);

            try
            {
                DeleteSafeTopic(ns, topicName);

                TopicDescription        tdescription = ns.CreateTopic(topicName);
                SubscriptionDescription sdescription = new SubscriptionDescription(topicName, name)
                {
                    RequiresSession  = false,
                    LockDuration     = TimeSpan.FromMinutes(1),
                    MaxDeliveryCount = 10,
                    EnableDeadLetteringOnMessageExpiration = true,
                    AutoDeleteOnIdle = TimeSpan.FromMinutes(5)
                };

                var outsd = ns.CreateSubscription(sdescription);
                Assert.IsTrue(null != tdescription);
                Assert.IsTrue(null != sdescription);
                Assert.IsFalse(outsd.RequiresSession);
                Assert.IsTrue(outsd.EnableDeadLetteringOnMessageExpiration);

                IEnumerable <SubscriptionDescription> suscriptions = ns.GetSubscriptions(topicName);
                Assert.IsTrue(suscriptions.First().Name.Equals(name));
            }
            finally
            {
                DeleteSafeTopic(ns, topicName);
            }
        }
コード例 #8
0
        static void Main(string[] args)
        {
            // Connect to the Service Bus namespace using a SAS Url with the Manage permission
            _nameSpaceManager = NamespaceManager.CreateFromConnectionString(_connectionString);

            // Create the topic if it does not already exist
            if (!_nameSpaceManager.TopicExists(_topicName))
            {
                _nameSpaceManager.CreateTopic(_topicName);
            }

            // Create a new subscription with a message filter to only accept
            // messages from the ServiceBusSender - to be used by the ServiceBusSubscriber web application
            SqlFilter externalSubscriptionFilter = new SqlFilter("From = 'ServiceBusSender'");

            if (!_nameSpaceManager.SubscriptionExists(_topicName, _externalSubscriptionName))
            {
                _nameSpaceManager.CreateSubscription(_topicName, _externalSubscriptionName, externalSubscriptionFilter);
            }

            // Create a new subscription with a message filter to only accept
            // response messages from the ServiceBusSubscriber - to be used by the Azure Function subscriber
            SqlFilter functionSubscriptionFilter = new SqlFilter("From = 'ServiceBusSubscriber'");

            if (!_nameSpaceManager.SubscriptionExists(_topicName, _functionSubscriptionName))
            {
                _nameSpaceManager.CreateSubscription(_topicName, _functionSubscriptionName, functionSubscriptionFilter);
            }
        }
コード例 #9
0
        public void TestTopic()
        {
            string           name        = "testTopic2";
            NamespaceManager ns          = NamespaceManager.CreateFromConnectionString(serviceBusConnectionString);
            TopicDescription description = ns.CreateTopic(name);

            Assert.IsTrue(null != description);

            try
            {
                TopicDescription testTopic2 = ns.GetTopics().FirstOrDefault(e => e.Path.Equals("testTopic2", StringComparison.InvariantCultureIgnoreCase));
                Assert.IsNotNull(testTopic2);

                if (!ns.TopicExists(name, out description))
                {
                    Assert.Fail("Topic did not exist");
                }
                else
                {
                    Assert.IsTrue(null != description);
                }
            }
            finally
            {
                ns.DeleteTopic(name);
                if (ns.TopicExists(name, out description))
                {
                    Assert.Fail("Topic was not deleted");
                }
            }
        }
コード例 #10
0
        public void TestSubscription()
        {
            string           name         = "testSubscription";
            string           topicName    = "testTopicSubscription";
            NamespaceManager ns           = NamespaceManager.CreateFromConnectionString(serviceBusConnectionString);
            TopicDescription tdescription = ns.CreateTopic(topicName);

            Assert.IsTrue(null != tdescription);
            SubscriptionDescription sdescription = ns.CreateSubscription(topicName, name);

            Assert.IsTrue(null != sdescription);

            if (!ns.SubscriptionExists(topicName, name, out sdescription))
            {
                Assert.Fail("Subscription did not exist");
            }
            else
            {
                Assert.IsTrue(null != sdescription);
                ns.DeleteSubscription(topicName, name);
                if (ns.SubscriptionExists(topicName, name, out sdescription))
                {
                    Assert.Fail("Subscription was not deleted");
                }

                ns.DeleteTopic(topicName);
                if (ns.TopicExists(name, out tdescription))
                {
                    Assert.Fail("Topic was not deleted");
                }
            }
        }
コード例 #11
0
        private static void CreateTopicAndSubscriptionsWithFilters()
        {
            // PART 1 - CREATE THE TOPIC
            Console.WriteLine("Creating the topic");
            namespaceManager = NamespaceManager.CreateFromConnectionString(ServiceBusconnectionString);
            if (!namespaceManager.TopicExists(TopicName))
            {
                // Configure Topic Settings.
                var topic = new TopicDescription(TopicName)
                {
                    MaxSizeInMegabytes       = 1024,
                    DefaultMessageTimeToLive = TimeSpan.FromMinutes(5)
                };

                namespaceManager.CreateTopic(topic);
            }

            Console.WriteLine("Done!");
            Console.WriteLine("Creating subscriptions");

            //PART 2 - CREATE THE SUBSCRIPTIONS

            namespaceManager.CreateSubscription(TopicName, SubscriptionAllMessages, new SqlFilter("1=1"));
            namespaceManager.CreateSubscription(TopicName, SubscriptionColorBlueSize10Orders, new SqlFilter("color = 'blue' AND quantity = 10"));
            namespaceManager.CreateSubscription(TopicName, SubscriptionColorRed, new SqlFilter("color = 'red'"));
            namespaceManager.CreateSubscription(TopicName, SubscriptionHighPriorityOrders, new CorrelationFilter("high"));
        }
コード例 #12
0
        public void TestGetMoreThanOneSubscription()
        {
            string name1     = "testSubscription1";
            string name2     = "testSubscription2";
            string topicName = "TestGetMoreThanOneSubscription";

            NamespaceManager ns = NamespaceManager.CreateFromConnectionString(serviceBusConnectionString);

            try
            {
                DeleteSafeTopic(ns, topicName);

                TopicDescription tdescription = ns.CreateTopic(topicName);
                Assert.IsTrue(null != tdescription);
                SubscriptionDescription sdescription1 = ns.CreateSubscription(topicName, name1);
                Assert.IsTrue(null != sdescription1);
                SubscriptionDescription sdescription2 = ns.CreateSubscription(topicName, name2);
                Assert.IsTrue(null != sdescription2);

                IEnumerable <SubscriptionDescription> suscriptions = ns.GetSubscriptions(topicName);
                Assert.IsTrue(suscriptions.ElementAt(0).Name.Equals(name1));
                Assert.IsTrue(suscriptions.ElementAt(1).Name.Equals(name2));
            }
            finally
            {
                DeleteSafeTopic(ns, topicName);
            }
        }
コード例 #13
0
 public void CreateTopic(string topicPath)
 {
     if (!_manager.TopicExists(topicPath))
     {
         _manager.CreateTopic(topicPath);
     }
 }
コード例 #14
0
ファイル: AzureServiceBus.cs プロジェクト: 403016605/CQRS
        protected virtual void CheckTopicExists(NamespaceManager namespaceManager, string eventTopicName, string eventSubscriptionNames)
        {
            // Configure Queue Settings
            var eventTopicDescription = new TopicDescription(eventTopicName)
            {
                MaxSizeInMegabytes       = 5120,
                DefaultMessageTimeToLive = new TimeSpan(0, 25, 0),
                EnablePartitioning       = true,
                EnableBatchedOperations  = true
            };

            // Create the topic if it does not exist already
            if (!namespaceManager.TopicExists(eventTopicDescription.Path))
            {
                namespaceManager.CreateTopic(eventTopicDescription);
            }

            if (!namespaceManager.SubscriptionExists(eventTopicDescription.Path, eventSubscriptionNames))
            {
                namespaceManager.CreateSubscription
                (
                    new SubscriptionDescription(eventTopicDescription.Path, eventSubscriptionNames)
                {
                    DefaultMessageTimeToLive = new TimeSpan(0, 25, 0),
                    EnableBatchedOperations  = true,
                    EnableDeadLetteringOnFilterEvaluationExceptions = true
                }
                );
            }
        }
コード例 #15
0
        protected override void CreateTopic(NamespaceManager nsm)
        {
            if (nsm.TopicExists(topicName))
            {
                nsm.DeleteTopic(topicName);
            }

            if (!nsm.TopicExists(topicName))
            {
                // this topic will use Topic related Shared Access Keys
                TopicDescription td = new TopicDescription(topicName);

                // create a new SAS for topic
                tsKey = SharedAccessAuthorizationRule.GenerateRandomKey();
                td.Authorization.Add(new SharedAccessAuthorizationRule(tsKeyName, tsKey, new[] { AccessRights.Send }));
                tlKey = SharedAccessAuthorizationRule.GenerateRandomKey();
                td.Authorization.Add(new SharedAccessAuthorizationRule(tlKeyName, tlKey, new[] { AccessRights.Listen }));

                nsm.CreateTopic(td);
            }

            _tc = _cf.CreateTopicClient(nsName, topicName, tsKeyName, tsKey);


            if (!nsm.SubscriptionExists(topicName, topicSubName))
            {
                nsm.CreateSubscription(topicName, topicSubName);
            }
            _sc = _cf.CreateSubscriptionClient(nsName, topicName, topicSubName, tlKeyName, tlKey);
        }
コード例 #16
0
ファイル: ServiceBus.cs プロジェクト: lptingley/Kinectonitor
        public ServiceBus Subscribe <T>(Action <T> receiveHandler)
        {
            SetupServiceBusEnvironment();
            var topicName        = string.Format("Topic_{0}", typeof(T).Name);
            var subscriptionName = string.Format("Subscription_{0}", typeof(T).Name);

            if (!_namespaceManager.TopicExists(topicName))
            {
                _namespaceManager.CreateTopic(topicName);
            }

            var topic = _namespaceManager.GetTopic(topicName);

            SubscriptionDescription subscription;

            if (!_namespaceManager.SubscriptionExists(topic.Path, subscriptionName))
            {
                subscription = _namespaceManager.CreateSubscription(topic.Path, subscriptionName);
            }
            else
            {
                subscription = _namespaceManager.GetSubscription(topic.Path, subscriptionName);
            }

            var subscriptionClient = _messagingFactory.CreateSubscriptionClient(topicName, subscriptionName, ReceiveMode.ReceiveAndDelete);

            _subscribers.Add(new Tuple <string, SubscriptionClient>(topicName, subscriptionClient));

            Begin <T>(receiveHandler, subscriptionClient);

            return(this);
        }
コード例 #17
0
        public bool Create()
        {
            bool result = true;

            try
            {
                Logger.LogMessage("Creating service bus topic...");
                Logger.LogMessage("Please provide the name for topic: ");
                Name = Console.ReadLine();
                Logger.LogMessage(string.Format("Checking if topic with name {0} already exists in service bus namespace...", Name));
                if (!CheckIfExists(Name))
                {
                    Logger.LogMessage(string.Format(CultureInfo.InvariantCulture, "Creating Topic with name {0} in service bus namespace", Name));
                    // Generate Topic description
                    TopicDescription topicDescription = GenerateTopicDescription(Name);
                    // Create topic
                    Logger.LogMessage(string.Format(CultureInfo.InvariantCulture, "Creating topic with name {0} in service bus namespace...", Name));
                    nameSpaceManager.CreateTopic(topicDescription);
                    Logger.LogMessage(string.Format(CultureInfo.InvariantCulture, "Topic with name {0} created in service bus namespace", Name));
                }
                else
                {
                    result = false;
                }
            }
            catch
            {
                result = false;
                throw;
            }
            return(result);
        }
コード例 #18
0
        public QueueServer(string saveFilePath, string fileQueueName, string statusQueueName)
        {
            _fileQueueName   = fileQueueName;
            _statusQueueName = statusQueueName;
            _saveFilePath    = saveFilePath;

            CreateQueue(_fileQueueName);
            CreateQueue(_statusQueueName);

            NamespaceManager namespaceManager = NamespaceManager.Create();

            _topicName = ServerConstants.SettingTopicName;


            if (!namespaceManager.TopicExists(_topicName))
            {
                namespaceManager.CreateTopic(new TopicDescription(_topicName)
                {
                    EnablePartitioning = false
                });
            }

            _topicClient = TopicClient.Create(_topicName);
            FileSystemWatcher watcher = new FileSystemWatcher();

            watcher.Path                = Directory.GetCurrentDirectory();
            watcher.Filter              = ServerConstants.ConfigFileName;
            watcher.NotifyFilter        = NotifyFilters.LastWrite;
            watcher.Changed            += this.OnChanged;
            watcher.EnableRaisingEvents = true;
        }
コード例 #19
0
        private void CreateTopicsAndSubscriptions()
        {
            // If the topic exists, delete it.
            if (NamespaceMgr.TopicExists(TopicPath))
            {
                NamespaceMgr.DeleteTopic(TopicPath);
            }

            // Create the topic.
            NamespaceMgr.CreateTopic(TopicPath);

            // Subscription for all jobs
            NamespaceMgr.CreateSubscription
                (TopicPath, Models.JobType.FullStack.ToString());

            // Subscriptions for Specific jobs
            NamespaceMgr.CreateSubscription(TopicPath, Models.JobType.WebDeveloper.ToString(),
                                            new SqlFilter($"JobType = '{Models.JobType.WebDeveloper.ToString()}'"));

            NamespaceMgr.CreateSubscription(TopicPath, Models.JobType.DBA.ToString(),
                                            new SqlFilter($"JobType = '{Models.JobType.DBA.ToString()}'"));

            NamespaceMgr.CreateSubscription(TopicPath, Models.JobType.MiddleTierDeveloper.ToString(),
                                            new SqlFilter($"JobType = '{Models.JobType.MiddleTierDeveloper.ToString()}'"));

            // Correlation subscription for Tester
            NamespaceMgr.CreateSubscription(TopicPath, Models.JobType.Testing.ToString(),
                                            new CorrelationFilter($"{Models.JobType.Testing.ToString()}"));
        }
コード例 #20
0
        public void TestSubscriptionRequiresSession()
        {
            string name      = "TestSubscriptionRequiresSession";
            string topicName = "TestSubscriptionRequiresSession";

            NamespaceManager ns = NamespaceManager.CreateFromConnectionString(serviceBusConnectionString);

            try
            {
                DeleteSafeTopic(ns, topicName);

                TopicDescription        tdescription = ns.CreateTopic(topicName);
                SubscriptionDescription sdescription = new SubscriptionDescription(topicName, name);
                sdescription.RequiresSession = false;
                var outsd = ns.CreateSubscription(sdescription);
                Assert.IsTrue(null != tdescription);
                Assert.IsTrue(null != sdescription);
                Assert.IsFalse(outsd.RequiresSession);

                IEnumerable <SubscriptionDescription> suscriptions = ns.GetSubscriptions(topicName);
                Assert.IsTrue(suscriptions.First().Name.Equals(name));
            }
            finally
            {
                DeleteSafeTopic(ns, topicName);
            }
        }
コード例 #21
0
        public async void Init(MessageReceived messageReceivedHandler) {
            this.random = new Random();

            //ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.AutoDetect;
            
            // Tcp mode does not work when I run in a VM (VirtualBox) and the host 
            // is using a wireless connection. Hard coding to Http.
            ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http;

            string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
            this.factory = MessagingFactory.CreateFromConnectionString(connectionString);
            this.namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);

            if (!namespaceManager.TopicExists(topicName)) {
                namespaceManager.CreateTopic(topicName);
            }

            this.subscriptionName = Guid.NewGuid().ToString();

            // Not needed really, it's a GUID...
            if (!namespaceManager.SubscriptionExists(topicName, subscriptionName)) {
                namespaceManager.CreateSubscription(topicName, subscriptionName);
            }

            this.topicClient = factory.CreateTopicClient(topicName);

            this.subClient = factory.CreateSubscriptionClient(topicName, subscriptionName);

            while (true) {
                await ReceiveMessageTaskAsync(messageReceivedHandler);
            }
        }
コード例 #22
0
        public void CreateTopic(
            string path,
            bool requiresDuplicateDetection = false,
            TimeSpan?duplicateDetectionHistoryTimeWindow = null,
            TimeSpan?defaultMessageTTL = null,
            bool enableFilteringMessagesBeforePublishing = false
            )
        {
            try
            {
                TopicDescription topicDescription = new TopicDescription(path)
                {
                    RequiresDuplicateDetection              = requiresDuplicateDetection,
                    DuplicateDetectionHistoryTimeWindow     = duplicateDetectionHistoryTimeWindow ?? TimeSpan.FromHours(1),
                    DefaultMessageTimeToLive                = defaultMessageTTL ?? TimeSpan.FromHours(1),
                    EnableFilteringMessagesBeforePublishing = enableFilteringMessagesBeforePublishing
                };

                if (!_servicebusNamespaceManager.TopicExists(path))
                {
                    _servicebusNamespaceManager.CreateTopic(topicDescription);
                }
            }
            catch (Exception ex)
            {
                new NotImplementedException();
            }
        }
コード例 #23
0
        static void Main(string[] args)
        {
            GetUserCredentials();
            TokenProvider tokenProvider = null;
            Uri serviceUri = null;
            CreateTokenProviderAndServiceUri(out tokenProvider, out serviceUri);

            NamespaceManager namespaceManager = new NamespaceManager(serviceUri, tokenProvider);
            Console.WriteLine("Creating Topic 'IssueTrackingTopic'...");
            if (namespaceManager.TopicExists("IssueTrackingTopic"))
                namespaceManager.DeleteTopic("IssueTrackingTopic");

            MessagingFactory factory = null;
            TopicDescription myTopic = namespaceManager.CreateTopic(TopicName);
            // Criar duas Subscrições
            Console.WriteLine("Creating Subscriptions 'AuditSubscription' and 'AgentSubscription'...");
            SubscriptionDescription myAuditSubscription = namespaceManager.CreateSubscription((myTopic.Path, "AuditSubscription");
            SubscriptionDescription myAgentSubscription = namespaceManager.CreateSubscription(myTopic.Path, "AgentSubscription");
            TopicClient myTopicClient = CreateTopicClient(serviceUri, tokenProvider, myTopic, out factory);
            List<BrokeredMessage> messageList = new List<BrokeredMessage>();
            messageList.Add(CreateIssueMessage("1", "First message information"));
            messageList.Add(CreateIssueMessage("2", "Second message information"));
            messageList.Add(CreateIssueMessage("3", "Third message information"));
            Console.WriteLine("\nSending messages to topic...");
            SendListOfMessages(messageList, myTopicClient);

            Console.WriteLine("\nFinished sending messages, press ENTER to clean up and exit.");
            myTopicClient.Close();
            Console.ReadLine();
            namespaceManager.DeleteTopic(TopicName);
        }
コード例 #24
0
 protected void EnsureTopicExists(string topic)
 {
     if (!namespaceManager.TopicExists(topic))
     {
         namespaceManager.CreateTopic(topic);
     }
 }
コード例 #25
0
        public bool Create(IDictionary <string, object> apiRequestModel)
        {
            bool result = false;

            if (null != apiRequestModel)
            {
                TopicModel topicRequest = apiRequestModel.ToEntity <TopicModel>();
                if (null != topicRequest)
                {
                    Logger.LogMessage(string.Format("Checking if topic with name {0} already exists in service bus namespace...", topicRequest.Name));
                    if (!CheckIfExists(topicRequest.Name))
                    {
                        Logger.LogMessage(string.Format(CultureInfo.InvariantCulture, "Creating Topic with name {0} in service bus namespace", topicRequest.Name));
                        TopicDescription topicDescription = GenerateTopicDescription(topicRequest);
                        if (null != topicDescription)
                        {
                            Logger.LogMessage(string.Format(CultureInfo.InvariantCulture, "Creating topic with name {0} in service bus namespace...", topicRequest.Name));
                            nameSpaceManager.CreateTopic(topicDescription);
                            Logger.LogMessage(string.Format(CultureInfo.InvariantCulture, "Topic with name {0} created in service bus namespace", topicRequest.Name));
                            result = true;
                        }
                    }
                }
            }
            return(result);
        }
コード例 #26
0
        static void SendMessage()
        {
            TokenProvider tokenProvider = _namespaceManager.Settings.TokenProvider;

            if (!_namespaceManager.TopicExists("DataCollectionTopic"))
            {
                _namespaceManager.CreateTopic("DataCollectionTopic");

                if (!_namespaceManager.SubscriptionExists("DataCollectionTopic", "Inventory"))
                {
                    _namespaceManager.CreateSubscription("DataCollectionTopic", "Inventory");
                }
                if (!_namespaceManager.SubscriptionExists("DataCollectionTopic", "Dashboard"))
                {
                    _namespaceManager.CreateSubscription("DataCollectionTopic", "Dashboard");
                }

                MessagingFactory factory = MessagingFactory.Create(_namespaceManager.Address, tokenProvider);

                BrokeredMessage message = new BrokeredMessage();//can pass a user defined class too
                message.Label = "SalesReport";
                message.Properties["StoreName"] = "Nike";
                message.Properties["MachineID"] = "POS1";

                BrokeredMessage message1 = new BrokeredMessage();//can pass a user defined class too
                message1.Label = "SalesRep";
                message1.Properties["StoreName"] = "Addidas";
                message1.Properties["MachineID"] = "POS3";

                MessageSender sender = factory.CreateMessageSender("DataCollectionTopic");
                sender.Send(message);
                sender.Send(message1);
                Console.WriteLine("Message Sent Succefully");
            }
        }
コード例 #27
0
        static void Main(string[] args)
        {
            NamespaceManager manager = NamespaceManager.Create(); // Automatycznie bierze informacje z App.config

            Console.WriteLine(manager.Address.ToString());
            //Wolę na początku - wygodniej "zaczynamy" zawsze od zera
            manager.DeleteTopic("2016obliczenia"); //Kasuje temat i subskrypcje
            manager.DeleteQueue("2016wynik");

            //Tworzenie Topics - tematu
            TopicDescription td = new TopicDescription("2016obliczenia");

            //Nie przewidujemy dużego ruchu nie wymagamy partycjonowania
            td.EnablePartitioning = false;
            //Wymagamy wykrywania duplikatów - by klient 2 razy nie wysłał tego samego polecenia
            td.RequiresDuplicateDetection = true;
            //Nie pozwalamy na tematy tylko w pamięci; chcemy żeby klient był pewien że wysłał wiadomość = wiadomość zostanie przetworzona
            td.EnableExpress = false;
            manager.CreateTopic(td); //Tworzenie tematu

            //Suma i średnia będzie wyliczana gdy opowiednia własciwość zostanie zdefiniowana
            manager.CreateSubscription("2016obliczenia", "log", new SqlFilter("1=1"));
            manager.CreateSubscription("2016obliczenia", "dodaj", new SqlFilter("operation=1"));
            manager.CreateSubscription("2016obliczenia", "odejmij", new SqlFilter("operation=2"));

            QueueDescription qd = new QueueDescription("2016wynik");

            qd.RequiresSession = true;
            manager.CreateQueue(qd);
            Console.WriteLine("Done, Enter");
            Console.ReadLine();
        }
コード例 #28
0
 private void InitTopic()
 {
     //Service Bus接続文字列の取得
     connectionString = CloudConfigurationManager
                        .GetSetting("ServiceBusConnectionString");
     //Topic名の取得
     TopicName = CloudConfigurationManager
                 .GetSetting("TopicName");
     //Subscription名の取得
     subscripitionname = CloudConfigurationManager
                         .GetSetting("DefaultSubscriptionName");
     triggersubName = CloudConfigurationManager
                      .GetSetting("TriggerSubscriptionName");
     //NamespaceManagerインスタンスの作成
     nsMan = NamespaceManager
             .CreateFromConnectionString(connectionString);
     //Topicの存在をチェックし、存在しない場合は新規作成
     if (nsMan.TopicExists(TopicName) == false)
     {
         nsMan.CreateTopic(TopicName);
     }
     //2種類のSubscriptionの存在をチェックし、存在しない場合は新規作成
     if (nsMan.SubscriptionExists(TopicName, subscripitionname) == false)
     {
         nsMan.CreateSubscription(TopicName, subscripitionname);
     }
     if (nsMan.SubscriptionExists(TopicName, triggersubName) == false)
     {
         nsMan.CreateSubscription(TopicName, triggersubName);
     }
 }
コード例 #29
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SubscriptionReceiver"/> class,
        /// automatically creating the topic and subscription if they don't exist.
        /// </summary>
        public SubscriptionReceiver(MessagingSettings settings, string topic, string subscription)
        {
            this.settings     = settings;
            this.subscription = subscription;

            this.tokenProvider = TokenProvider.CreateSharedSecretTokenProvider(settings.TokenIssuer, settings.TokenAccessKey);
            this.serviceUri    = ServiceBusEnvironment.CreateServiceUri(settings.ServiceUriScheme, settings.ServiceNamespace, settings.ServicePath);

            var messagingFactory = MessagingFactory.Create(this.serviceUri, tokenProvider);

            this.client = messagingFactory.CreateSubscriptionClient(topic, subscription);

            var manager = new NamespaceManager(this.serviceUri, this.tokenProvider);

            try
            {
                manager.CreateTopic(
                    new TopicDescription(topic)
                {
                    RequiresDuplicateDetection          = true,
                    DuplicateDetectionHistoryTimeWindow = TimeSpan.FromMinutes(30)
                });
            }
            catch (MessagingEntityAlreadyExistsException)
            { }

            try
            {
                manager.CreateSubscription(topic, subscription);
            }
            catch (MessagingEntityAlreadyExistsException)
            { }
        }
コード例 #30
0
        static void Main(string[] args)
        {
            // Connect to the Service Bus namespace using a SAS Url with the Manage permission
            _nameSpaceManager = NamespaceManager.CreateFromConnectionString(_connectionString);

            // Create the topic if it does not already exist
            if (!_nameSpaceManager.TopicExists(_topicName))
            {
                _nameSpaceManager.CreateTopic(_topicName);
            }

            // Create a new subscription with a message filter to only accept
            // messages from the ServiceBusSender - to be used by the ServiceBusSubscriber web application
            SqlFilter subscriptionFilter = new SqlFilter("Customer = 'Customer2'");

            if (!_nameSpaceManager.SubscriptionExists(_topicName, _subscriptionName))
            {
                _nameSpaceManager.CreateSubscription(_topicName, _subscriptionName, subscriptionFilter);
            }

            Console.WriteLine($"**** {_subscriptionName} has started ***");
            Task.Run(() => ProcessMessages());
            Console.WriteLine($"*** {_subscriptionName} is Running. Press any key to stop. ***");
            Console.Read();
            Console.WriteLine($"*** {_subscriptionName} is Stopping ***");
            _isStopped = true;
        }
コード例 #31
0
        private static void CreateTopic()
        {
            NamespaceManager namespaceManager = NamespaceManager.Create();

            Console.WriteLine("\nCreating Topic " + TopicName + "...");
            try
            {
                // Delete if exists
                if (namespaceManager.TopicExists(TopicName))
                {
                    namespaceManager.DeleteTopic(TopicName);
                }

                TopicDescription myTopic = namespaceManager.CreateTopic(TopicName);

                Console.WriteLine("Creating Subscriptions 'AuditSubscription' and 'AgentSubscription'...");
                SubscriptionDescription myAuditSubscription = namespaceManager.CreateSubscription(myTopic.Path, "AuditSubscription");
                SubscriptionDescription myAgentSubscription = namespaceManager.CreateSubscription(myTopic.Path, "AgentSubscription");
            }
            catch (MessagingException e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
        }
コード例 #32
0
        public AzureServiceBusMessageQueue(string connectionString, string inputQueue)
        {
            log.Info("Initializing Azure Service Bus transport with logical input queue '{0}'", inputQueue);

            namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);

            InputQueue = inputQueue;

            log.Info("Ensuring that topic '{0}' exists", TopicName);
            if (!namespaceManager.TopicExists(TopicName))
            {
                try
                {
                    namespaceManager.CreateTopic(TopicName);
                }
                catch
                {
                    // just assume the call failed because the topic already exists - if GetTopic below
                    // fails, then something must be wrong, and then we just want to fail immediately
                }
            }

            topicDescription = namespaceManager.GetTopic(TopicName);
            GetOrCreateSubscription(InputQueue);

            log.Info("Creating topic client");
            topicClient = TopicClient.CreateFromConnectionString(connectionString, topicDescription.Path);

            log.Info("Creating subscription client");
            subscriptionClient = SubscriptionClient.CreateFromConnectionString(connectionString, TopicName, InputQueue);
        }
コード例 #33
0
ファイル: WorkerRole.cs プロジェクト: jplane/AzureATLMeetup
        public override bool OnStart()
        {
            ServicePointManager.DefaultConnectionLimit = 12;

            var connectionString = CloudConfigurationManager.GetSetting("topicConnectionString");
            var topicName = CloudConfigurationManager.GetSetting("topicName");

            _nsMgr = NamespaceManager.CreateFromConnectionString(connectionString);

            if (!_nsMgr.TopicExists(topicName))
            {
                _nsMgr.CreateTopic(topicName);
            }

            if (!_nsMgr.SubscriptionExists(topicName, "audit"))
            {
                _nsMgr.CreateSubscription(topicName, "audit");
            }

            _client = SubscriptionClient.CreateFromConnectionString(connectionString, topicName, "audit", ReceiveMode.ReceiveAndDelete);

            var result = base.OnStart();

            Trace.TraceInformation("NTM.Auditing has been started");

            return result;
        }
コード例 #34
0
 private void EnsureTopicExists(string topic)
 {
     if (!_namespaceManager.TopicExists(topic))
     {
         _logger.Value.InfoFormat("Topic {0} does not exist, creating it.");
         _namespaceManager.CreateTopic(topic);
     }
 }
コード例 #35
0
        static void Main(string[] args)
        {
            Console.Write("Enter some subscription name: ");
            string name = Console.ReadLine();

            var serviceNamespace = "msswit2013relay";
            var issuerName = "owner";
            var issuerSecret = "IqyIwa7gNjBO89HT+3Vd1CcoBbyibvcv6Hd92J+FtPg=";

            Uri uri = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace, string.Empty);

            TokenProvider tokenProvider = TokenProvider.CreateSharedSecretTokenProvider(issuerName, issuerSecret);
            NamespaceManager namespaceManager = new NamespaceManager(uri, tokenProvider);

            if (!namespaceManager.TopicExists("MyTopic"))
            {
                namespaceManager.CreateTopic(new TopicDescription("MyTopic"));
            }

            Console.WriteLine("topic ready");

            if (!namespaceManager.SubscriptionExists("MyTopic", "subscription-" + name))
            {
                namespaceManager.CreateSubscription("MyTopic", "subscription-" + name);
            }

            Console.WriteLine("subscription ready");

            MessagingFactory factory = MessagingFactory.Create(uri, tokenProvider);
            MessageReceiver receiver = factory.CreateMessageReceiver("MyTopic/subscriptions/subscription-" + name);
            while (true)
            {
                BrokeredMessage receivedMessage = receiver.Receive();
                if (receivedMessage != null)
                {
                    try
                    {
                        Console.WriteLine("label: {0}", receivedMessage.Label);
                        Console.WriteLine("login: {0}", receivedMessage.Properties["login"]);
                        Console.WriteLine("pass: {0}", receivedMessage.GetBody<ServiceBusTestMessage>().Password);
                        receivedMessage.Complete();
                    }
                    catch (Exception e)
                    {
                        receivedMessage.Abandon();
                        Console.WriteLine(e.Message);
                    }
                }
                else
                {
                    Thread.Sleep(new TimeSpan(0, 0, 10));
                }
            }
        }
コード例 #36
0
        public ServiceBusMessageBus(string connectionString, string topicName, ISerializer serializer = null) {
            _topicName = topicName;
            _serializer = serializer ?? new JsonNetSerializer();
            _subscriptionName = "MessageBus";
            _namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
            if (!_namespaceManager.TopicExists(_topicName))
                _namespaceManager.CreateTopic(_topicName);

            _topicClient = TopicClient.CreateFromConnectionString(connectionString, _topicName);
            if (!_namespaceManager.SubscriptionExists(_topicName, _subscriptionName))
                _namespaceManager.CreateSubscription(_topicName, _subscriptionName);

            _subscriptionClient = SubscriptionClient.CreateFromConnectionString(connectionString, _topicName, _subscriptionName, ReceiveMode.ReceiveAndDelete);
            _subscriptionClient.OnMessageAsync(OnMessageAsync, new OnMessageOptions { AutoComplete = true });
        }
コード例 #37
0
ファイル: Bus.cs プロジェクト: anlcan/coapp.org
        public Bus() {
            connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
            namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);

            // Configure Topic Settings
            var td = new TopicDescription(topicName);
            td.MaxSizeInMegabytes = 5120;
            td.DefaultMessageTimeToLive = new TimeSpan(0, 1, 0);

            if (!namespaceManager.TopicExists(topicName)) {
                namespaceManager.CreateTopic(topicName);
            }

            factory = MessagingFactory.CreateFromConnectionString(connectionString);
            sender = factory.CreateMessageSender(topicName);
        }
コード例 #38
0
        public CoAppRepositoryDaemonMain() {
            connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
            namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);

            // Configure Topic Settings
            var td1 = new TopicDescription(regenSiteTopic) {
                MaxSizeInMegabytes = 5120,
                DefaultMessageTimeToLive = new TimeSpan(0, 1, 0)
            };

            if (!namespaceManager.TopicExists(regenSiteTopic)) {
                namespaceManager.CreateTopic(regenSiteTopic);
            }

            factory = MessagingFactory.CreateFromConnectionString(connectionString);
            _running = true;
        }
コード例 #39
0
        public AzureServiceBusMessageQueue(string connectionString, string inputQueue)
        {
            try
            {
                log.Info("Initializing Azure Service Bus transport with logical input queue '{0}'", inputQueue);

                namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);

                InputQueue = inputQueue;

                log.Info("Ensuring that topic '{0}' exists", TopicName);
                if (!namespaceManager.TopicExists(TopicName))
                {
                    try
                    {
                        namespaceManager.CreateTopic(TopicName);
                    }
                    catch
                    {
                        // just assume the call failed because the topic already exists - if GetTopic below
                        // fails, then something must be wrong, and then we just want to fail immediately
                    }
                }

                topicDescription = namespaceManager.GetTopic(TopicName);

                log.Info("Creating topic client");
                topicClient = TopicClient.CreateFromConnectionString(connectionString, topicDescription.Path);

                // if we're in one-way mode, just quit here
                if (inputQueue == null) return;

                GetOrCreateSubscription(InputQueue);

                log.Info("Creating subscription client");
                subscriptionClient = SubscriptionClient.CreateFromConnectionString(connectionString, TopicName, InputQueue, ReceiveMode.PeekLock);
            }
            catch (Exception e)
            {
                throw new ApplicationException(
                    string.Format(
                        "An error occurred while initializing Azure Service Bus with logical input queue '{0}'",
                        inputQueue), e);
            }
        }
コード例 #40
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TopicSender"/> class, 
        /// automatically creating the given topic if it does not exist.
        /// </summary>
        protected TopicSender(ServiceBusSettings settings, string topic, RetryStrategy retryStrategy)
        {
            this.settings = settings;
            this.topic = topic;

            this.tokenProvider = TokenProvider.CreateSharedSecretTokenProvider(settings.TokenIssuer, settings.TokenAccessKey);
            this.serviceUri = ServiceBusEnvironment.CreateServiceUri(settings.ServiceUriScheme, settings.ServiceNamespace, settings.ServicePath);

            // TODO: This could be injected.
            this.retryPolicy = new RetryPolicy<ServiceBusTransientErrorDetectionStrategy>(retryStrategy);
            this.retryPolicy.Retrying +=
                (s, e) =>
                {
                    var handler = this.Retrying;
                    if (handler != null)
                    {
                        handler(this, EventArgs.Empty);
                    }

                    Trace.TraceWarning("An error occurred in attempt number {1} to send a message: {0}", e.LastException.Message, e.CurrentRetryCount);
                };

            var factory = MessagingFactory.Create(this.serviceUri, this.tokenProvider);
            this.topicClient = factory.CreateTopicClient(this.topic);

            var namespaceManager = new NamespaceManager(this.serviceUri, this.tokenProvider);

            foreach (var topicSettings in settings.Topics)
            {
                if (!namespaceManager.TopicExists(topicSettings.Path))
                {
                    namespaceManager.CreateTopic(topicSettings.Path);
                }

                foreach (var subscriptionSetting in topicSettings.Subscriptions)
                {
                    if (!namespaceManager.SubscriptionExists(topicSettings.Path, subscriptionSetting.Name))
                    {
                        namespaceManager.CreateSubscription(topicSettings.Path, subscriptionSetting.Name);
                    }
                }
            }
        }
コード例 #41
0
        private void SetupAzureServiceBus()
        {
            Composable.GetExport<IXLogger>().Debug("Azure ServiceBus Scaling - INIT");
            _namespaceManager = NamespaceManager.CreateFromConnectionString(_connectionString);

            if (!_namespaceManager.TopicExists(TopicPath))
            {
                Composable.GetExport<IXLogger>().Debug("Creating Topic for Azure Service Bus");
                TopicDescription td = _namespaceManager.CreateTopic(TopicPath);
            }
            if (!_namespaceManager.SubscriptionExists(TopicPath, _sid))
            {
                _namespaceManager.CreateSubscription(TopicPath, _sid);
                Composable.GetExport<IXLogger>().Debug("Creating Subscription for Azure Service Bus");
            }
            _topicClient = TopicClient.CreateFromConnectionString(_connectionString, TopicPath);
            _subscriptionClient = SubscriptionClient.CreateFromConnectionString(_connectionString, TopicPath, _sid);
        }
コード例 #42
0
        public async Task SetupAsync(Type[] allMessageTypes, Type[] recievingMessageTypes)
        {
            _logger.Debug("Starting the setup of AzureServicebusTransport...");

            _namespaceManager = NamespaceManager.CreateFromConnectionString(_configuration.GetConnectionString());
            _messagingFactory = MessagingFactory.CreateFromConnectionString(_configuration.GetConnectionString());

            _messageTypes = allMessageTypes;

            var sendCommandTypes = _messageTypes
                .Where(t => typeof (IBusCommand)
                    .IsAssignableFrom(t));

            var sendEventTypes = _messageTypes
                .Where(t => typeof(IBusEvent)
                    .IsAssignableFrom(t));

            var recieveCommandTypes = recievingMessageTypes
                .Where(t => typeof(IBusCommand)
                    .IsAssignableFrom(t));

            var recieveEventTypes = recievingMessageTypes
                .Where(t => typeof(IBusEvent)
                    .IsAssignableFrom(t));

            if (_configuration.GetEnableTopicAndQueueCreation())
            {
                foreach (var type in sendCommandTypes)
                {
                    var path = PathFactory.QueuePathFor(type);
                    if (!_namespaceManager.QueueExists(path))
                        await _namespaceManager.CreateQueueAsync(path);

                    var client = _messagingFactory.CreateQueueClient(path);
                    client.PrefetchCount = 10; //todo;: in config?

                    var eventDrivenMessagingOptions = new OnMessageOptions
                    {
                        AutoComplete = true, //todo: in config?
                        MaxConcurrentCalls = 10 //todo: in config?
                    };
                    eventDrivenMessagingOptions.ExceptionReceived += OnExceptionReceived;
                    client.OnMessageAsync(OnMessageRecieved, eventDrivenMessagingOptions);

                    if (!_queues.TryAdd(type, client))
                    {
                        _logger.Error("Could not add the queue with type: {0}", type.FullName);
                    }
                }
                foreach (var type in sendEventTypes)
                {
                    var path = PathFactory.TopicPathFor(type);
                    if (!_namespaceManager.TopicExists(path))
                        _namespaceManager.CreateTopic(path);

                    var client = _messagingFactory.CreateTopicClient(path);

                    if (!_topics.TryAdd(type, client))
                    {
                        _logger.Error("Could not add the topic with type: {0}", type.FullName);
                    }


                }
            }

            _logger.Debug("Setup of AzureServicebusTransport completed!");

            throw new NotImplementedException();
        }
コード例 #43
0
        static void CreateTopicsAndSubscriptions(NamespaceManager namespaceManager)
        {
            // Create a topic and 3 subscriptions.
            topicDescription = namespaceManager.CreateTopic(Conts.TopicName);
            try
            {
                namespaceManager.DeleteSubscription(topicDescription.Path, Conts.SubAllMessages);
            }
            catch { }

            try
            {
                namespaceManager.DeleteSubscription(topicDescription.Path, Conts.SubHolding);
            }
            catch { }

            try
            {
                namespaceManager.DeleteSubscription(topicDescription.Path, Conts.YoungHorses);
            }
            catch { }

            try
            {
                namespaceManager.DeleteSubscription(topicDescription.Path, Conts.OldHorses);
            }
            catch { }

            namespaceManager.CreateSubscription(topicDescription.Path, Conts.SubAllMessages, new TrueFilter());
            namespaceManager.CreateSubscription(topicDescription.Path, Conts.SubHolding, new FalseFilter());
            //namespaceManager.CreateSubscription(topicDescription.Path, Conts.YoungHorses, new TrueFilter());
            //namespaceManager.CreateSubscription(topicDescription.Path, Conts.OldHorses, new TrueFilter());

            namespaceManager.CreateSubscription(topicDescription.Path, Conts.YoungHorses, new SqlFilter("HorseId > 5"));
            namespaceManager.CreateSubscription(topicDescription.Path, Conts.OldHorses, new SqlFilter("HorseId <= 5"));
        }
コード例 #44
0
        public void CreateTopic_WhenSslErrorOccurs_MessagingExceptionExceptionIsThrown()
        {
            string topicName = Guid.NewGuid().ToString();

            Uri validCertUri = ServiceBusHelper.GetLocalHttpsEndpoint();
            Uri invalidCertUri = new Uri("https://localhost:9355/ServiceBusDefaultNamespace");
            TokenProvider tokenProvider = TokenProvider.CreateWindowsTokenProvider(new Uri[] { validCertUri });
            NamespaceManager nsManager = new NamespaceManager(invalidCertUri, tokenProvider);

            Assert.Throws<MessagingException>(() => nsManager.CreateTopic(topicName));
        }
コード例 #45
0
        private void CreateTopic(NamespaceManager ns, string dc, string path)
        {
            using( new TraceLogicalScope(source, "CreateTopic"))
            {
                source.TraceEvent(TraceEventType.Verbose, 0, "Creating Topic '{0}'", path);

                ns.CreateTopic(path);
            }
        }
コード例 #46
0
        private void CreateTopicIfNotExists(NamespaceManager namespaceManager, TopicSettings topic)
        {
            var topicDescription =
                new TopicDescription(topic.Path)
                {
                    RequiresDuplicateDetection = true,
                    DuplicateDetectionHistoryTimeWindow = topic.DuplicateDetectionHistoryTimeWindow,
                };

            try
            {
                namespaceManager.CreateTopic(topicDescription);
            }
            catch (MessagingEntityAlreadyExistsException) { }
        }