/// <summary>
 ///     Starts the listener.
 /// </summary>
 public void Start(Func <BrokeredMessage, MessageReleaseAction> messageHandler)
 {
     lock (lockObject) {
         MessageHandler     = messageHandler;
         cancellationSource = new CancellationTokenSource();
         Task.Factory.StartNew(() =>
                               ReceiveMessages(cancellationSource.Token),
                               cancellationSource.Token);
         dynamicThrottling.Start(cancellationSource.Token);
     }
 }
 /// <summary>
 ///     Starts the listener.
 /// </summary>
 public void Start(Func <BrokeredMessage, MessageReleaseAction> messageHandler)
 {
     lock (lockObject) {
         // If it's not null, there is already a listening task.
         if (cancellationSource == null)
         {
             MessageHandler     = messageHandler;
             cancellationSource = new CancellationTokenSource();
             Task.Factory.StartNew(() => AcceptSession(cancellationSource.Token), cancellationSource.Token);
             dynamicThrottling.Start(cancellationSource.Token);
         }
     }
 }
Exemple #3
0
        public void Start(CancellationToken cancellationToken)
        {
            Task.Factory.StartNew(
                () => {
                try {
                    foreach (var key in GetThrottlingEnumerable(enqueuedKeys.GetConsumingEnumerable(cancellationToken), cancellationToken))
                    {
                        if (!cancellationToken.IsCancellationRequested)
                        {
                            ProcessPartition(key);
                        }
                        else
                        {
                            EnqueueIfNotExists(key);
                            return;
                        }
                    }
                } catch (OperationCanceledException) { }
            },
                TaskCreationOptions.LongRunning);

            // Query through all partitions to check for pending events, as there could be
            // stored events that were never published before the system was rebooted.
            Task.Factory.StartNew(
                () => {
                foreach (var partitionKey in queue.GetPartitionsWithPendingEvents())
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        return;
                    }

                    EnqueueIfNotExists(partitionKey);
                }
            },
                TaskCreationOptions.LongRunning);

            dynamicThrottling.Start(cancellationToken);
        }