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


C# SubscriptionClient类代码示例

本文整理汇总了C#中SubscriptionClient的典型用法代码示例。如果您正苦于以下问题:C# SubscriptionClient类的具体用法?C# SubscriptionClient怎么用?C# SubscriptionClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

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

示例2: InitialiseTopic

        public void InitialiseTopic()
        {
            ServicePointManager.DefaultConnectionLimit = 12;

            string connectionString = CloudConfigurationManager.GetSetting("ServiceBus.TopicConnectionString");
            _topicClient = SubscriptionClient.CreateFromConnectionString(connectionString, "recreateindex", "WebRoles");

            Task.Run(() =>
            {
                _topicClient.OnMessage(async receivedMessage =>
                {
                    var sequenceNumber = receivedMessage.SequenceNumber;
                    try
                    {
                        await _throttling.Execute(async () => ReCreateSearcher());
                    }
                    catch (Exception ex)
                    {
                        //no idea why it does not work but well, log it
                        Trace.TraceWarning("Exception occurred during the read of message '" + sequenceNumber + "': " + ex.Message);
                    }
                }, new OnMessageOptions {
                    AutoComplete = true
                });

                _completedEvent.WaitOne();
            });
        }
开发者ID:robstoll,项目名称:farmfinder,代码行数:28,代码来源:Global.asax.cs

示例3: InitServiceBusConnection

        private void InitServiceBusConnection()
        {
            string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");

            // Initialize clients
            _client = SubscriptionClient.CreateFromConnectionString(connectionString, "channel_sava", "twitter_follower_email");
        }
开发者ID:varadzhakov,项目名称:work,代码行数:7,代码来源:WorkerRole.cs

示例4: ReliableSubscriptionClient

 public ReliableSubscriptionClient(string sbNamespace, TokenProvider tokenProvider, string path, string name, RetryPolicy<ServiceBusTransientErrorDetectionStrategy> policy)
     : base(sbNamespace, tokenProvider, path, policy)
 {
     //create the queue if it doesn't exist
     bool needsCreation = false;
     try
     {
         needsCreation = !mRetryPolicy.ExecuteAction<bool>(() => mNamespaceManager.SubscriptionExists(path,name));
     }
     catch (MessagingEntityNotFoundException)
     {
         needsCreation = true;
     }
     if (needsCreation)
     {
         try
         {
             mRetryPolicy.ExecuteAction<SubscriptionDescription>(() => mNamespaceManager.CreateSubscription(path,name));
         }
         catch (MessagingEntityAlreadyExistsException)
         {
             //ignore this exception because queue already exists
         }
     }
     mRetryPolicy.ExecuteAction(() => mSubscriptionClient = mMessagingFactory.CreateSubscriptionClient(path,name));
 }
开发者ID:HaishiBai,项目名称:ReliableServiceBusClients,代码行数:26,代码来源:ReliableSubscriptionClient.cs

示例5: Initialize

 public static void Initialize()
 {
     if (null == OrdersTopicClient)
     {
         try
         {
             string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBusTopics.ConnectionString");
             // string connectionString = RoleEnvironment.GetConfigurationSettingValue("Microsoft.ServiceBusTopics.ConnectionString");
             var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
             if (!namespaceManager.TopicExists("OrderTopic"))
             {
                 namespaceManager.CreateTopic("OrderTopic");
             }
             if (!namespaceManager.SubscriptionExists("OrderTopic", "OrderMessages"))
             {
                 namespaceManager.CreateSubscription("OrderTopic", "OrderMessages");
             }
             // Initialize the connection to Service Bus Topics
             OrdersTopicClient = TopicClient.CreateFromConnectionString(connectionString, "OrderTopic");
             SubClient = SubscriptionClient.CreateFromConnectionString(connectionString, "OrderTopic", "OrderMessages");
            
         }
         catch (Exception ex)
         {
             string str = ex.Message;
         }
     }
 }
开发者ID:Kgabo707,项目名称:azure-guidance,代码行数:28,代码来源:ServiceBusTopicHelper.cs

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

示例7: GetSubscriptionClient

        private async Task<SubscriptionClient> GetSubscriptionClient()
        {
            if (_subscriptionClient != null) return _subscriptionClient;

            _subscriptionClient = await _queueManager.CreateSubscriptionReceiver(_topicPath, _subscriptionName);
            _subscriptionClient.PrefetchCount = ConcurrentHandlerLimit;
            return _subscriptionClient;
        }
开发者ID:Joshscorp,项目名称:Nimbus,代码行数:8,代码来源:NimbusSubscriptionMessageReceiver.cs

示例8: GetSubscriptionClient

        private async Task<SubscriptionClient> GetSubscriptionClient()
        {
            if (_subscriptionClient != null) return _subscriptionClient;

            _subscriptionClient = await _queueManager.CreateSubscriptionReceiver(_topicPath, _subscriptionName);
            _subscriptionClient.PrefetchCount = _prefetchCountSetting;
            return _subscriptionClient;
        }
开发者ID:Royal-Jay,项目名称:Zombus,代码行数:8,代码来源:OnReceiveSubscriptionMessageReceiver.cs

示例9: Create

		public SubscriptionObserver Create(IServiceBus bus, SubscriptionRouter router)
		{
			string path = bus.ControlBus.Endpoint.Address.Uri.AbsolutePath;


			var client = new SubscriptionClient(bus, router, _subscriptionServiceUri, _timeout);

			return client;
		}
开发者ID:vinayreddym,项目名称:MassTransit,代码行数:9,代码来源:SubscriptionClientConfiguratorImpl.cs

示例10: CanUnregisterProviderIfRegistered

        public void CanUnregisterProviderIfRegistered()
        {
            var mockHandler = CreateMockHandler(() => CreateResponseMessageWithStatus(HttpStatusCode.OK));

            ISubscriptionClient client = new SubscriptionClient(subscriptionData, mockHandler);
            bool worked = client.UnregisterResourceType("someResource");

            Assert.IsTrue(worked);
        }
开发者ID:Viachaslau,项目名称:azure-sdk-tools,代码行数:9,代码来源:SubscriptionsClientTest.cs

示例11: Subscribe

        public async Task Subscribe(Subscriber subscriber, MessageType messageType, ContextBag context)
        {
            //When the subscriber is running V6 and UseLegacyMessageDrivenSubscriptionMode is enabled at the subscriber the 'subcriber.Endpoint' value is null
            var endpoint = subscriber.Endpoint ?? subscriber.TransportAddress.Split('@').First();
            var subscriptionClient = new SubscriptionClient { TransportAddress = subscriber.TransportAddress, Endpoint = endpoint };

            var attempts = 0;

            //note: since we have a design that can run into concurrency exceptions we perform a few retries
            // we should redesign this in the future to use a separate doc per subscriber and message type
            do
            {
                try
                {
                    using (var session = OpenAsyncSession())
                    {
                        var subscriptionDocId = Subscription.FormatId(messageType);

                        var subscription = await session.LoadAsync<Subscription>(subscriptionDocId).ConfigureAwait(false);

                        if (subscription == null)
                        {
                            subscription = new Subscription
                            {
                                Id = subscriptionDocId,
                                MessageType = messageType,
                                Subscribers = new List<SubscriptionClient>()
                            };

                            await session.StoreAsync(subscription).ConfigureAwait(false);
                        }

                        if (!subscription.Subscribers.Contains(subscriptionClient))
                        {
                            subscription.Subscribers.Add(subscriptionClient);
                        }
                        else
                        {
                            var savedSubscription = subscription.Subscribers.Single(s => s.Equals(subscriptionClient));
                            if (savedSubscription.Endpoint != subscriber.Endpoint)
                            {
                                savedSubscription.Endpoint = subscriber.Endpoint;
                            }
                        }

                        await session.SaveChangesAsync().ConfigureAwait(false);
                    }

                    return;
                }
                catch (ConcurrencyException)
                {
                    attempts++;
                }
            } while (attempts < 5);
        }
开发者ID:areicher,项目名称:NServiceBus.RavenDB,代码行数:56,代码来源:SubscriptionPersister.cs

示例12: DiscardSubscriptionClient

        private void DiscardSubscriptionClient()
        {
            var subscriptionClient = _subscriptionClient;
            _subscriptionClient = null;

            if (subscriptionClient == null) return;
            if (subscriptionClient.IsClosed) return;

            subscriptionClient.Close();
        }
开发者ID:Royal-Jay,项目名称:Zombus,代码行数:10,代码来源:OnReceiveSubscriptionMessageReceiver.cs

示例13: Start

        /// <summary>
        /// 
        /// </summary>
        /// <param name="address"></param>
        /// <param name="tryProcessMessage"></param>
        public void Start(Address address, Action<BrokeredMessage> tryProcessMessage)
        {
            _cancelRequested = false;

            _tryProcessMessage = tryProcessMessage;

            _subscriptionClient = SubscriptionClientCreator.Create(address, EventType);

            if (_subscriptionClient != null) _subscriptionClient.BeginReceiveBatch(BatchSize, TimeSpan.FromSeconds(ServerWaitTime), OnMessage, null);
        }
开发者ID:afyles,项目名称:NServiceBus,代码行数:15,代码来源:AzureServiceBusTopicNotifier.cs

示例14: AzureServiceBusEventDispatcherReceiver

        public AzureServiceBusEventDispatcherReceiver(string connectionString, IEventDispatcher innerEventDispatcher, IEventStore eventStore, string topicName, string subscriptionName)
        {
            _innerEventDispatcher = innerEventDispatcher;
            _eventStore = eventStore;

            AzureHelpers.EnsureTopicExists(connectionString, topicName);
            AzureHelpers.EnsureSubscriptionExists(connectionString, topicName, subscriptionName);

            _subscriptionClient = SubscriptionClient.CreateFromConnectionString(connectionString, topicName, subscriptionName);

            _workerThread = new Thread(DoWork);
        }
开发者ID:RichieYang,项目名称:Cirqus,代码行数:12,代码来源:AzureServiceBusEventDispatcherReceiver.cs

示例15: CanGetListOfRegisteredProviders

        public void CanGetListOfRegisteredProviders()
        {
            string[] knownResourceTypes = {"website", "mobileservice"};

            var mockHandler = CreateMockHandler(() => CreateListResourcesResponseMessage(
                new ProviderResource {Type = "Website", State = "Unregistered"},
                new ProviderResource {Type = "Mobileservice", State = "Registered"}
                ));

            ISubscriptionClient client = new SubscriptionClient(subscriptionData, mockHandler);
            IEnumerable<ProviderResource> actualResourceTypes = client.ListResources(knownResourceTypes);

            CollectionAssert.AreEquivalent(knownResourceTypes, actualResourceTypes.Select(rt => rt.Type.ToLower()).ToList());
        }
开发者ID:Viachaslau,项目名称:azure-sdk-tools,代码行数:14,代码来源:SubscriptionsClientTest.cs


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