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


C# NamespaceManager.SubscriptionExists方法代码示例

本文整理汇总了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;
        }
开发者ID:jplane,项目名称:AzureATLMeetup,代码行数:27,代码来源:WorkerRole.cs

示例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);
            }
        }
开发者ID:DonKarlssonSan,项目名称:CumulusChat,代码行数:32,代码来源:ChatApplication.cs

示例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));
                }
            }
        }
开发者ID:quaternion94,项目名称:msswit2013-lab2,代码行数:54,代码来源:Program.cs

示例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 });
        }
开发者ID:jmkelly,项目名称:Foundatio,代码行数:15,代码来源:ServiceBusMessageBus.cs

示例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);
                    }
                }
            }
        }
开发者ID:pebblecode,项目名称:EducationPathways,代码行数:47,代码来源:TopicSender.cs

示例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);
        }
开发者ID:acandocodecamp,项目名称:xsockets,代码行数:18,代码来源:AzureServiceBusScaleout.cs

示例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");
        }
开发者ID:hlaubisch,项目名称:BrewBuddy,代码行数:20,代码来源:TemperatureTap.cs

示例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);
            }
        }
开发者ID:pebblecode,项目名称:EducationPathways,代码行数:51,代码来源:SubscriptionReceiver.cs

示例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


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