예제 #1
0
 public NonNullConverterValueBinder(IStorageQueue queue, IConverter <TInput, IStorageQueueMessage> converter,
                                    IMessageEnqueuedWatcher messageEnqueuedWatcher)
 {
     _queue     = queue;
     _converter = converter;
     _messageEnqueuedWatcher = messageEnqueuedWatcher;
 }
예제 #2
0
        public QueueListener(IStorageQueue queue,
                             IStorageQueue poisonQueue,
                             ITriggerExecutor <IStorageQueueMessage> triggerExecutor,
                             IWebJobsExceptionHandler exceptionHandler,
                             ILoggerFactory loggerFactory,
                             SharedQueueWatcher sharedWatcher,
                             IQueueConfiguration queueConfiguration,
                             QueueProcessor queueProcessor = null,
                             TimeSpan?maxPollingInterval   = null)
        {
            if (queueConfiguration == null)
            {
                throw new ArgumentNullException("queueConfiguration");
            }

            if (queueConfiguration.BatchSize <= 0)
            {
                throw new ArgumentException("BatchSize must be greater than zero.");
            }

            if (queueConfiguration.MaxDequeueCount <= 0)
            {
                throw new ArgumentException("MaxDequeueCount must be greater than zero.");
            }

            _timer              = new TaskSeriesTimer(this, exceptionHandler, Task.Delay(0));
            _queue              = queue;
            _poisonQueue        = poisonQueue;
            _triggerExecutor    = triggerExecutor;
            _exceptionHandler   = exceptionHandler;
            _queueConfiguration = queueConfiguration;

            // if the function runs longer than this, the invisibility will be updated
            // on a timer periodically for the duration of the function execution
            _visibilityTimeout = TimeSpan.FromMinutes(10);

            if (sharedWatcher != null)
            {
                // Call Notify whenever a function adds a message to this queue.
                sharedWatcher.Register(queue.Name, this);
                _sharedWatcher = sharedWatcher;
            }

            EventHandler <PoisonMessageEventArgs> poisonMessageEventHandler = _sharedWatcher != null ? OnMessageAddedToPoisonQueue : (EventHandler <PoisonMessageEventArgs>)null;

            _queueProcessor = queueProcessor ?? CreateQueueProcessor(
                _queue.SdkObject, _poisonQueue != null ? _poisonQueue.SdkObject : null,
                loggerFactory, _queueConfiguration, poisonMessageEventHandler);

            TimeSpan maximumInterval = _queueProcessor.MaxPollingInterval;

            if (maxPollingInterval.HasValue && maximumInterval > maxPollingInterval.Value)
            {
                // enforce the maximum polling interval if specified
                maximumInterval = maxPollingInterval.Value;
            }

            _delayStrategy = new RandomizedExponentialBackoffStrategy(QueuePollingIntervals.Minimum, maximumInterval);
        }
        private async Task RegisterWithSharedBlobListenerAsync(
            string hostId,
            SharedBlobListener sharedBlobListener,
            BlobServiceClient blobClient,
            QueueClient hostBlobTriggerQueue,
            IMessageEnqueuedWatcher messageEnqueuedWatcher,
            CancellationToken cancellationToken)
        {
            BlobTriggerExecutor triggerExecutor = new BlobTriggerExecutor(hostId, _functionDescriptor, _input, new BlobReceiptManager(blobClient),
                                                                          new BlobTriggerQueueWriter(hostBlobTriggerQueue, messageEnqueuedWatcher), _loggerFactory.CreateLogger <BlobListener>());

            await sharedBlobListener.RegisterAsync(blobClient, _container, triggerExecutor, cancellationToken).ConfigureAwait(false);
        }
        public QueueListener(IStorageQueue queue,
                             IStorageQueue poisonQueue,
                             ITriggerExecutor <IStorageQueueMessage> triggerExecutor,
                             IDelayStrategy delayStrategy,
                             IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
                             TraceWriter trace,
                             SharedQueueWatcher sharedWatcher,
                             IQueueConfiguration queueConfiguration)
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            if (queueConfiguration == null)
            {
                throw new ArgumentNullException("queueConfiguration");
            }

            if (queueConfiguration.BatchSize <= 0)
            {
                throw new ArgumentException("BatchSize must be greater than zero.");
            }

            if (queueConfiguration.MaxDequeueCount <= 0)
            {
                throw new ArgumentException("MaxDequeueCount must be greater than zero.");
            }

            _timer           = new TaskSeriesTimer(this, backgroundExceptionDispatcher, Task.Delay(0));
            _queue           = queue;
            _poisonQueue     = poisonQueue;
            _triggerExecutor = triggerExecutor;
            _delayStrategy   = delayStrategy;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _trace = trace;
            _queueConfiguration = queueConfiguration;

            if (sharedWatcher != null)
            {
                // Call Notify whenever a function adds a message to this queue.
                sharedWatcher.Register(queue.Name, this);
                _sharedWatcher = sharedWatcher;
            }

            EventHandler poisonMessageEventHandler = _sharedWatcher != null ? OnMessageAddedToPoisonQueue : (EventHandler)null;

            _queueProcessor = CreateQueueProcessor(
                _queue.SdkObject, _poisonQueue != null ? _poisonQueue.SdkObject : null,
                _trace, _queueConfiguration, poisonMessageEventHandler);
        }
        private async Task RegisterWithSharedBlobListenerAsync(
            string hostId,
            SharedBlobListener sharedBlobListener,
            IStorageBlobClient blobClient,
            IStorageQueue hostBlobTriggerQueue,
            IMessageEnqueuedWatcher messageEnqueuedWatcher,
            CancellationToken cancellationToken)
        {
            BlobTriggerExecutor triggerExecutor = new BlobTriggerExecutor(hostId, _functionId, _input,
                                                                          BlobETagReader.Instance, new BlobReceiptManager(blobClient),
                                                                          new BlobTriggerQueueWriter(hostBlobTriggerQueue, messageEnqueuedWatcher));

            await sharedBlobListener.RegisterAsync(_container, triggerExecutor, cancellationToken);
        }
        public QueueListener(IStorageQueue queue,
            IStorageQueue poisonQueue,
            ITriggerExecutor<IStorageQueueMessage> triggerExecutor,
            IDelayStrategy delayStrategy,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            TraceWriter trace,
            SharedQueueWatcher sharedWatcher,
            IQueueConfiguration queueConfiguration)
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            if (queueConfiguration == null)
            {
                throw new ArgumentNullException("queueConfiguration");
            }

            if (queueConfiguration.BatchSize <= 0)
            {
                throw new ArgumentException("BatchSize must be greater than zero.");
            }

            if (queueConfiguration.MaxDequeueCount <= 0)
            {
                throw new ArgumentException("MaxDequeueCount must be greater than zero.");
            }

            _timer = new TaskSeriesTimer(this, backgroundExceptionDispatcher, Task.Delay(0));
            _queue = queue;
            _poisonQueue = poisonQueue;
            _triggerExecutor = triggerExecutor;
            _delayStrategy = delayStrategy;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _trace = trace;
            _queueConfiguration = queueConfiguration;

            if (sharedWatcher != null)
            {
                // Call Notify whenever a function adds a message to this queue.
                sharedWatcher.Register(queue.Name, this);
                _sharedWatcher = sharedWatcher;
            }

            EventHandler poisonMessageEventHandler = _sharedWatcher != null ? OnMessageAddedToPoisonQueue : (EventHandler)null;
            _queueProcessor = CreateQueueProcessor(
                _queue.SdkObject, _poisonQueue != null ? _poisonQueue.SdkObject : null,
                _trace, _queueConfiguration, poisonMessageEventHandler);
        }
예제 #7
0
        public QueueListener(IStorageQueue queue,
                             IStorageQueue poisonQueue,
                             ITriggerExecutor <IStorageQueueMessage> triggerExecutor,
                             IDelayStrategy delayStrategy,
                             IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
                             TextWriter log,
                             SharedQueueWatcher sharedWatcher,
                             int batchSize,
                             int maxDequeueCount)
        {
            if (log == null)
            {
                throw new ArgumentNullException("log");
            }

            if (batchSize <= 0)
            {
                throw new ArgumentOutOfRangeException("batchSize");
            }

            if (maxDequeueCount <= 0)
            {
                throw new ArgumentOutOfRangeException("maxDequeueCount");
            }

            _timer           = new TaskSeriesTimer(this, backgroundExceptionDispatcher, Task.Delay(0));
            _queue           = queue;
            _poisonQueue     = poisonQueue;
            _triggerExecutor = triggerExecutor;
            _delayStrategy   = delayStrategy;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _log = log;

            if (sharedWatcher != null)
            {
                // Call Notify whenever a function adds a message to this queue.
                sharedWatcher.Register(queue.Name, this);
                _sharedWatcher = sharedWatcher;
            }

            _batchSize         = batchSize;
            _newBatchThreshold = (uint)_batchSize / 2;
            _maxDequeueCount   = (uint)maxDequeueCount;
        }
예제 #8
0
 internal static void RegisterSharedWatcherWithQueueProcessor(QueueProcessor queueProcessor, IMessageEnqueuedWatcher sharedWatcher)
 {
     if (sharedWatcher != null)
     {
         EventHandler <PoisonMessageEventArgs> poisonMessageEventHandler = (object sender, PoisonMessageEventArgs e) =>
         {
             sharedWatcher.Notify(e.PoisonQueue.Name);
         };
         queueProcessor.MessageAddedToPoisonQueue += poisonMessageEventHandler;
     }
 }
 private async Task<IListener> CreateBlobDiscoveryToQueueMessageListenerAsync(string hostId,
     SharedBlobListener sharedBlobListener,
     IStorageBlobClient blobClient,
     IStorageQueue hostBlobTriggerQueue,
     IMessageEnqueuedWatcher messageEnqueuedWatcher,
     CancellationToken cancellationToken)
 {
     BlobTriggerExecutor triggerExecutor = new BlobTriggerExecutor(hostId, _functionId, _input,
         BlobETagReader.Instance, new BlobReceiptManager(blobClient),
         new BlobTriggerQueueWriter(hostBlobTriggerQueue, messageEnqueuedWatcher));
     await sharedBlobListener.RegisterAsync(_container, triggerExecutor, cancellationToken);
     return new BlobListener(sharedBlobListener);
 }
예제 #10
0
 public QueueAsyncCollector(QueueClient queue, IMessageEnqueuedWatcher messageEnqueuedWatcher)
 {
     this._queue = queue;
     this._messageEnqueuedWatcher = messageEnqueuedWatcher;
 }
예제 #11
0
        internal static QueueProcessor CreateQueueProcessor(QueueClient queue, QueueClient poisonQueue, ILoggerFactory loggerFactory, IQueueProcessorFactory queueProcessorFactory,
                                                            QueuesOptions queuesOptions, IMessageEnqueuedWatcher sharedWatcher)
        {
            QueueProcessorOptions context = new QueueProcessorOptions(queue, loggerFactory, queuesOptions, poisonQueue);

            QueueProcessor queueProcessor = null;

            if (HostQueueNames.IsHostQueue(queue.Name))
            {
                // We only delegate to the processor factory for application queues,
                // not our built in control queues
                queueProcessor = new QueueProcessor(context);
            }
            else
            {
                queueProcessor = queueProcessorFactory.Create(context);
            }

            QueueListener.RegisterSharedWatcherWithQueueProcessor(queueProcessor, sharedWatcher);

            return(queueProcessor);
        }
 public BlobTriggerQueueWriter(IStorageQueue queue, IMessageEnqueuedWatcher watcher)
 {
     _queue = queue;
     Debug.Assert(watcher != null);
     _watcher = watcher;
 }
예제 #13
0
 internal SharedQueueWriter(IStorageQueue queue, IMessageEnqueuedWatcher watcher)
 {
     _queue = queue;
     Debug.Assert(watcher != null);
     _watcher = watcher;
 }
예제 #14
0
 internal static void RegisterSharedWatcherWithQueueProcessor(QueueProcessor queueProcessor, IMessageEnqueuedWatcher sharedWatcher)
 {
     if (sharedWatcher != null)
     {
         queueProcessor.MessageAddedToPoisonQueueAsync += (queueProcessor, e) =>
         {
             sharedWatcher.Notify(e.PoisonQueue.Name);
             return(Task.CompletedTask);
         };
     }
 }
예제 #15
0
        public QueueListener(QueueClient queue,
                             QueueClient poisonQueue,
                             ITriggerExecutor <QueueMessage> triggerExecutor,
                             IWebJobsExceptionHandler exceptionHandler,
                             ILoggerFactory loggerFactory,
                             SharedQueueWatcher sharedWatcher,
                             QueuesOptions queueOptions,
                             QueueProcessor queueProcessor,
                             FunctionDescriptor functionDescriptor,
                             string functionId           = null,
                             TimeSpan?maxPollingInterval = null)
        {
            if (queueOptions == null)
            {
                throw new ArgumentNullException(nameof(queueOptions));
            }

            if (queueProcessor == null)
            {
                throw new ArgumentNullException(nameof(queueProcessor));
            }

            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            if (queueOptions.BatchSize <= 0)
            {
                throw new ArgumentException("BatchSize must be greater than zero.");
            }

            if (queueOptions.MaxDequeueCount <= 0)
            {
                throw new ArgumentException("MaxDequeueCount must be greater than zero.");
            }

            _timer              = new TaskSeriesTimer(this, exceptionHandler, Task.Delay(0));
            _queue              = queue;
            _poisonQueue        = poisonQueue;
            _triggerExecutor    = triggerExecutor;
            _exceptionHandler   = exceptionHandler;
            _queueOptions       = queueOptions;
            _logger             = loggerFactory.CreateLogger <QueueListener>();
            _functionDescriptor = functionDescriptor ?? throw new ArgumentNullException(nameof(functionDescriptor));
            _functionId         = functionId ?? _functionDescriptor.Id;

            // if the function runs longer than this, the invisibility will be updated
            // on a timer periodically for the duration of the function execution
            _visibilityTimeout = TimeSpan.FromMinutes(10);

            if (sharedWatcher != null)
            {
                // Call Notify whenever a function adds a message to this queue.
                sharedWatcher.Register(queue.Name, this);
                _sharedWatcher = sharedWatcher;
            }

            _queueProcessor = queueProcessor;

            TimeSpan maximumInterval = _queueProcessor.QueuesOptions.MaxPollingInterval;

            if (maxPollingInterval.HasValue && maximumInterval > maxPollingInterval.Value)
            {
                // enforce the maximum polling interval if specified
                maximumInterval = maxPollingInterval.Value;
            }

            _delayStrategy = new RandomizedExponentialBackoffStrategy(QueuePollingIntervals.Minimum, maximumInterval);

            _scaleMonitorDescriptor          = new ScaleMonitorDescriptor($"{_functionId}-QueueTrigger-{_queue.Name}".ToLower(CultureInfo.InvariantCulture));
            _shutdownCancellationTokenSource = new CancellationTokenSource();
        }
 public BlobTriggerQueueWriter(QueueClient queue, IMessageEnqueuedWatcher watcher)
 {
     _queue = queue;
     Debug.Assert(watcher != null);
     _watcher = watcher;
 }
예제 #17
0
 public QueueAsyncCollector(IStorageQueue queue, IMessageEnqueuedWatcher messageEnqueuedWatcher)
 {
     this._queue = queue;
     this._messageEnqueuedWatcher = messageEnqueuedWatcher;
 }