本文整理汇总了C#中NamespaceManager.SubscriptionExists方法的典型用法代码示例。如果您正苦于以下问题:C# NamespaceManager.SubscriptionExists方法的具体用法?C# NamespaceManager.SubscriptionExists怎么用?C# NamespaceManager.SubscriptionExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NamespaceManager
的用法示例。
在下文中一共展示了NamespaceManager.SubscriptionExists方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnStart
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;
}
示例2: Init
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);
}
}
示例3: Main
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));
}
}
}
示例4: ServiceBusMessageBus
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 });
}
示例5: TopicSender
/// <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);
}
}
}
}
示例6: SetupAzureServiceBus
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);
}
示例7: InitializeSubscriptionClient
private void InitializeSubscriptionClient()
{
var tokenProvider = TokenProvider.CreateSharedSecretTokenProvider(OwnerIssuer, OwnerKey);
var serviceUrl = ServiceBusEnvironment.CreateServiceUri("sb", ServiceBusNamespace, string.Empty);
var namespaceManager = new NamespaceManager(serviceUrl, tokenProvider);
Trace.WriteLine("Initializing Subscription...", "Info");
SubscriptionDescription subscriptionDescription = new SubscriptionDescription(SensorApiTopic, "TemperatureTap");
if (!namespaceManager.SubscriptionExists(SensorApiTopic, "TemperatureTap"))
{
namespaceManager.CreateSubscription(subscriptionDescription);
}
Trace.WriteLine("Initialized Subscription.", "Info");
Trace.WriteLine("Initializing SubscriptionClient...", "Info");
var messagingFactory = MessagingFactory.Create(serviceUrl, tokenProvider);
_subscriptionClient = messagingFactory.CreateSubscriptionClient(SensorApiTopic, "TemperatureTap");
Trace.WriteLine("Initialized SubscriptionClient...", "Info");
}
示例8: SubscriptionReceiver
/// <summary>
/// Initializes a new instance of the <see cref="SubscriptionReceiver"/> class,
/// automatically creating the topic and subscription if they don't exist.
/// </summary>
protected SubscriptionReceiver(ServiceBusSettings settings, string topic, string subscription, bool processInParallel, RetryStrategy backgroundRetryStrategy)
{
this.settings = settings;
this.topic = topic;
this.subscription = subscription;
this.processInParallel = processInParallel;
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);
if (this.processInParallel)
{
this.client.PrefetchCount = 18;
}
else
{
this.client.PrefetchCount = 14;
}
this.dynamicThrottling =
new DynamicThrottling(
maxDegreeOfParallelism: 100,
minDegreeOfParallelism: 50,
penaltyAmount: 3,
workFailedPenaltyAmount: 5,
workCompletedParallelismGain: 1,
intervalForRestoringDegreeOfParallelism: 8000);
this.receiveRetryPolicy = new RetryPolicy<ServiceBusTransientErrorDetectionStrategy>(backgroundRetryStrategy);
this.receiveRetryPolicy.Retrying += (s, e) =>
{
this.dynamicThrottling.Penalize();
Trace.TraceWarning(
"An error occurred in attempt number {1} to receive a message from subscription {2}: {0}",
e.LastException.Message,
e.CurrentRetryCount,
this.subscription);
};
var namespaceManager = new NamespaceManager(this.serviceUri, this.tokenProvider);
if (!namespaceManager.SubscriptionExists(topic, subscription))
{
namespaceManager.CreateSubscription(topic, subscription);
}
}
示例9: SubscriptionExists
bool SubscriptionExists(NamespaceManager namespaceClient, string topicpath, string subscriptionname)
{
var key = topicpath + subscriptionname;
logger.InfoFormat("Checking cache for existence of subscription '{0}' on topic '{1}'", subscriptionname, topicpath);
var exists = rememberSubscriptionExistence.GetOrAdd(key, s => {
logger.InfoFormat("Checking namespace for subscription '{0}' on topic '{1}'", subscriptionname, topicpath);
return namespaceClient.SubscriptionExists(topicpath, subscriptionname);
});
logger.InfoFormat("Determined cache that the subscription '{0}' on topic '{1}' {2}", subscriptionname, topicpath, exists ? "exists" : "does not exist");
return exists;
}
开发者ID:danielmarbach,项目名称:NServiceBus.AzureServiceBus,代码行数:13,代码来源:AzureServicebusSubscriptionCreator.cs