本文整理汇总了C#中NamespaceManager.TopicExistsAsync方法的典型用法代码示例。如果您正苦于以下问题:C# NamespaceManager.TopicExistsAsync方法的具体用法?C# NamespaceManager.TopicExistsAsync怎么用?C# NamespaceManager.TopicExistsAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NamespaceManager
的用法示例。
在下文中一共展示了NamespaceManager.TopicExistsAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TopicShouldExistAsync
private async static Task TopicShouldExistAsync(NamespaceManager ns, TopicDescription topicDescription)
{
if (!await ns.TopicExistsAsync(topicDescription.Path))
{
throw new MessagingEntityNotFoundException("Topic: " + topicDescription.Path);
}
}
示例2: 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);
}
}
示例3: 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;
}
示例4: 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.");
}