当前位置: 首页>>代码示例>>C#>>正文


C# NamespaceManager.CreateTopicAsync方法代码示例

本文整理汇总了C#中NamespaceManager.CreateTopicAsync方法的典型用法代码示例。如果您正苦于以下问题:C# NamespaceManager.CreateTopicAsync方法的具体用法?C# NamespaceManager.CreateTopicAsync怎么用?C# NamespaceManager.CreateTopicAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NamespaceManager的用法示例。


在下文中一共展示了NamespaceManager.CreateTopicAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TopicCreateAsync

        private async static Task TopicCreateAsync(NamespaceManager ns, TopicDescription topicDescription)
        {
            if (!await ns.TopicExistsAsync(topicDescription.Path))
            {
                await ns.CreateTopicAsync(topicDescription);

                ServiceBusEventSource.Log.CreatedTopic(ns.Address.ToString(), topicDescription.Path);
            }
        }
开发者ID:RobinSoenen,项目名称:RedDog,代码行数:9,代码来源:MessagingFactoryTopicExtensions.cs

示例2: Post

		public async Task<IEnumerable<string>> Post()
		{
			var namespaceManager = new NamespaceManager(_address, _settings.TokenProvider);
			if (!await namespaceManager.TopicExistsAsync(TopicName))
			{
				var topicDescription = new TopicDescription(TopicName);
				var subscriptionDescription = new SubscriptionDescription(TopicName, SubscriptionName);
				topicDescription.EnablePartitioning = true;
				topicDescription.EnableBatchedOperations = false;
				subscriptionDescription.EnableBatchedOperations = false;
				await namespaceManager.CreateTopicAsync(topicDescription);
				await namespaceManager.CreateSubscriptionAsync(subscriptionDescription);
			}

			var messagingFactory = MessagingFactory.Create(_address, _settings);
			var client = messagingFactory.CreateTopicClient(TopicName);

			IEnumerable<string> result = ProcessPost(client);
			Task clientTask = client.CloseAsync();
			Task factoryTask = messagingFactory.CloseAsync();
			await Task.WhenAll(clientTask, factoryTask);

			return result;
		}
开发者ID:Neonsonne,项目名称:dbSpeed,代码行数:24,代码来源:AzureServiceBusTopicController.cs

示例3: Run

        public async Task Run(string namespaceAddress, string manageToken)
        {
            // This sample demonstrates how to use advanced filters with ServiceBus topics and subscriptions.
            // The sample creates a topic and 3 subscriptions with different filter definitions.
            // Each receiver will receive matching messages depending on the filter associated with a subscription.

            // NOTE:
            // This is primarily an example illustrating the management features related to setting up 
            // Service Bus subscriptions. It is DISCOURAGED for applications to routinely set up and 
            // tear down topics and subscriptions as a part of regular message processing. Managing 
            // topics and subscriptions is a system configuration operation. 

            // Create messaging factory and ServiceBus namespace client.
            var sharedAccessSignatureTokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(manageToken);
            var namespaceManager = new NamespaceManager(namespaceAddress, sharedAccessSignatureTokenProvider);

            Console.WriteLine("\nCreating a topic and 3 subscriptions.");

            // Create a topic and several subscriptions; clean house ahead of time
            if (await namespaceManager.TopicExistsAsync(TopicName))
            {
                await namespaceManager.DeleteTopicAsync(TopicName);
            }

            var topicDescription = await namespaceManager.CreateTopicAsync(TopicName);
            Console.WriteLine("Topic created.");

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

            // Create a subscription that'll receive all orders which have color "blue" and quantity 10.

            await namespaceManager.CreateSubscriptionAsync(
                topicDescription.Path,
                SubscriptionColorBlueSize10Orders,
                new SqlFilter("color = 'blue' AND quantity = 10"));
            Console.WriteLine(
                "Subscription {0} added with filter definition \"color = 'blue' AND quantity = 10\".",
                 SubscriptionColorBlueSize10Orders);

            // Create a subscription that'll receive all orders which have color "red"
            await namespaceManager.CreateSubscriptionAsync(
                topicDescription.Path,
                SubscriptionColorRed,
                new RuleDescription
                {
                    Name = "RedRule",
                    Filter = new SqlFilter("color = 'red'"),
                    Action = new SqlRuleAction(
                        "SET quantity = quantity / 2;" +
                        "REMOVE priority;" +
                        "SET sys.CorrelationId = 'low';")
                });
            Console.WriteLine("Subscription {0} added with filter definition \"color = 'red'\" and action definition.", SubscriptionColorRed);
     
            // Create a subscription that'll receive all high priority orders.
            namespaceManager.CreateSubscription(topicDescription.Path, SubscriptionHighPriorityOrders, 
                new CorrelationFilter { Label = "red", CorrelationId = "high"});
            Console.WriteLine("Subscription {0} added with correlation filter definition \"high\".", SubscriptionHighPriorityOrders);
     
            Console.WriteLine("Create completed.");


            await this.SendAndReceiveTestsAsync(namespaceAddress, sharedAccessSignatureTokenProvider);


            Console.WriteLine("Press [Enter] to quit...");
            Console.ReadLine();

            Console.WriteLine("\nDeleting topic and subscriptions from previous run if any.");

            try
            {
                namespaceManager.DeleteTopic(TopicName);
            }
            catch (MessagingEntityNotFoundException)
            {
                Console.WriteLine("No topic found to delete.");
            }

            Console.WriteLine("Delete completed.");
        }
开发者ID:Azure-Samples,项目名称:azure-servicebus-messaging-samples,代码行数:84,代码来源:Program.cs


注:本文中的NamespaceManager.CreateTopicAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。