コード例 #1
0
        public QueueTriggerBinding(string parameterName,
                                   QueueServiceClient queueServiceClient,
                                   QueueClient queue,
                                   ITriggerDataArgumentBinding <QueueMessage> argumentBinding,
                                   QueuesOptions queueOptions,
                                   IWebJobsExceptionHandler exceptionHandler,
                                   SharedQueueWatcher messageEnqueuedWatcherSetter,
                                   ILoggerFactory loggerFactory,
                                   IQueueProcessorFactory queueProcessorFactory,
                                   QueueCausalityManager queueCausalityManager)
        {
            _queueServiceClient = queueServiceClient ?? throw new ArgumentNullException(nameof(queueServiceClient));
            _queue                        = queue ?? throw new ArgumentNullException(nameof(queue));
            _argumentBinding              = argumentBinding ?? throw new ArgumentNullException(nameof(argumentBinding));
            _bindingDataContract          = CreateBindingDataContract(argumentBinding.BindingDataContract);
            _queueOptions                 = queueOptions ?? throw new ArgumentNullException(nameof(queueOptions));
            _exceptionHandler             = exceptionHandler ?? throw new ArgumentNullException(nameof(exceptionHandler));
            _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter ?? throw new ArgumentNullException(nameof(messageEnqueuedWatcherSetter));
            _queueCausalityManager        = queueCausalityManager ?? throw new ArgumentNullException(nameof(queueCausalityManager));

            _parameterName         = parameterName;
            _loggerFactory         = loggerFactory;
            _queueProcessorFactory = queueProcessorFactory;
            _converter             = CreateConverter(_queue);
            _logger = loggerFactory.CreateLogger <QueueTriggerBinding>();
        }
コード例 #2
0
        public QueueTriggerAttributeBindingProvider(INameResolver nameResolver,
                                                    QueueServiceClientProvider queueServiceClientProvider,
                                                    IOptions <QueuesOptions> queueOptions,
                                                    IWebJobsExceptionHandler exceptionHandler,
                                                    SharedQueueWatcher messageEnqueuedWatcherSetter,
                                                    ILoggerFactory loggerFactory,
                                                    IQueueProcessorFactory queueProcessorFactory,
                                                    QueueCausalityManager queueCausalityManager)
        {
            _queueServiceClientProvider = queueServiceClientProvider ?? throw new ArgumentNullException(nameof(queueServiceClientProvider));
            _queueOptions                 = (queueOptions ?? throw new ArgumentNullException(nameof(queueOptions))).Value;
            _exceptionHandler             = exceptionHandler ?? throw new ArgumentNullException(nameof(exceptionHandler));
            _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter ?? throw new ArgumentNullException(nameof(messageEnqueuedWatcherSetter));
            _queueCausalityManager        = queueCausalityManager ?? throw new ArgumentNullException(nameof(queueCausalityManager));

            _nameResolver          = nameResolver;
            _loggerFactory         = loggerFactory;
            _queueProcessorFactory = queueProcessorFactory;

            _innerProvider =
                new CompositeArgumentBindingProvider(
                    new ConverterArgumentBindingProvider <QueueMessage>(new CloudQueueMessageDirectConverter(), loggerFactory), // $$$: Is this the best way to handle a direct CloudQueueMessage? TODO (kasobol-msft) is this needed?
                    new ConverterArgumentBindingProvider <string>(new StorageQueueMessageToStringConverter(), loggerFactory),
                    new ConverterArgumentBindingProvider <byte[]>(new StorageQueueMessageToByteArrayConverter(), loggerFactory),
                    new ConverterArgumentBindingProvider <BinaryData>(new StorageQueueMessageToBinaryDataConverter(), loggerFactory),
                    new UserTypeArgumentBindingProvider(loggerFactory)); // Must come last, because it will attempt to bind all types.
        }
コード例 #3
0
        public QueueListenerFactory(
            QueueServiceClient queueServiceClient,
            QueueClient queue,
            QueuesOptions queueOptions,
            IWebJobsExceptionHandler exceptionHandler,
            SharedQueueWatcher messageEnqueuedWatcherSetter,
            ILoggerFactory loggerFactory,
            ITriggeredFunctionExecutor executor,
            IQueueProcessorFactory queueProcessorFactory,
            QueueCausalityManager queueCausalityManager,
            FunctionDescriptor descriptor
            )
        {
            _queue                        = queue ?? throw new ArgumentNullException(nameof(queue));
            _queueOptions                 = queueOptions ?? throw new ArgumentNullException(nameof(queueOptions));
            _exceptionHandler             = exceptionHandler ?? throw new ArgumentNullException(nameof(exceptionHandler));
            _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter ?? throw new ArgumentNullException(nameof(messageEnqueuedWatcherSetter));
            _executor                     = executor ?? throw new ArgumentNullException(nameof(executor));
            _descriptor                   = descriptor ?? throw new ArgumentNullException(nameof(descriptor));
            _queueCausalityManager        = queueCausalityManager ?? throw new ArgumentNullException(nameof(queueCausalityManager));

            _poisonQueue           = CreatePoisonQueueReference(queueServiceClient, queue.Name);
            _loggerFactory         = loggerFactory;
            _queueProcessorFactory = queueProcessorFactory;
        }
コード例 #4
0
        public ConsoleHostedService(
            IHostApplicationLifetime appLifetime,
            IQueueProcessorFactory processorFactory,
            ICache <Packet> cache
            )
        {
            _appLifetime = appLifetime;

            this.processorFactory = processorFactory;
            this.cache            = cache;
        }
コード例 #5
0
 public Orchestrator(IConfigurationReader configurationReader,
                     IQueueClientFactory queueClientFactory,
                     IMessageProcessorFactory messageProcessorFactory,
                     IQueueProcessorFactory queueProcessorFactory,
                     IConfigurationChangeManager configurationChangeManager)
 {
     IsProcessing                = false;
     _configurationReader        = configurationReader;
     _queueClientFactory         = queueClientFactory;
     _messageProcessorFactory    = messageProcessorFactory;
     _queueProcessorFactory      = queueProcessorFactory;
     _configurationChangeManager = configurationChangeManager;
 }
コード例 #6
0
 public StorageLoadBalancerQueue(
     StorageAccountProvider storageAccountProvider,
     IOptions <QueuesOptions> queueOptions,
     IWebJobsExceptionHandler exceptionHandler,
     SharedQueueWatcher sharedWatcher,
     ILoggerFactory loggerFactory,
     IQueueProcessorFactory queueProcessorFactory)
 {
     _storageAccountProvider = storageAccountProvider;
     _queueOptions           = queueOptions.Value;
     _exceptionHandler       = exceptionHandler;
     _sharedWatcher          = sharedWatcher;
     _loggerFactory          = loggerFactory;
     _queueProcessorFactory  = queueProcessorFactory;
 }
コード例 #7
0
 public QueueServiceClientProvider(
     IConfiguration configuration,
     AzureComponentFactory componentFactory,
     AzureEventSourceLogForwarder logForwarder,
     IOptions <QueuesOptions> queueOptions,
     ILoggerFactory loggerFactory,
     IQueueProcessorFactory queueProcessorFactory,
     SharedQueueWatcher messageEnqueuedWatcher)
     : base(configuration, componentFactory, logForwarder)
 {
     _queuesOptions          = queueOptions?.Value;
     _loggerFactory          = loggerFactory;
     _queueProcessorFactory  = queueProcessorFactory;
     _messageEnqueuedWatcher = messageEnqueuedWatcher;
 }
コード例 #8
0
        public QueueTriggerAttributeBindingProvider(INameResolver nameResolver,
                                                    QueueServiceClientProvider queueServiceClientProvider,
                                                    IOptions <QueuesOptions> queueOptions,
                                                    IWebJobsExceptionHandler exceptionHandler,
                                                    SharedQueueWatcher messageEnqueuedWatcherSetter,
                                                    ILoggerFactory loggerFactory,
                                                    IQueueProcessorFactory queueProcessorFactory)
        {
            _queueServiceClientProvider = queueServiceClientProvider ?? throw new ArgumentNullException(nameof(queueServiceClientProvider));
            _queueOptions                 = (queueOptions ?? throw new ArgumentNullException(nameof(queueOptions))).Value;
            _exceptionHandler             = exceptionHandler ?? throw new ArgumentNullException(nameof(exceptionHandler));
            _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter ?? throw new ArgumentNullException(nameof(messageEnqueuedWatcherSetter));

            _nameResolver          = nameResolver;
            _loggerFactory         = loggerFactory;
            _queueProcessorFactory = queueProcessorFactory;
        }
コード例 #9
0
        private List <IQueueProcessor> FindConfigsToAdd(List <ConfigurationEntry> configurations,
                                                        List <IQueueProcessor> processors,
                                                        IQueueClientFactory queueClientFactory,
                                                        IMessageProcessorFactory messageProcessorFactory,
                                                        IQueueProcessorFactory queueProcessorFactory)
        {
            var toAdd = new List <IQueueProcessor>();

            foreach (var config in configurations)
            {
                if (!config.Active)
                {
                    continue;
                }

                var found = false;
                foreach (var processor in processors)
                {
                    found = ((config.Alias == processor.Configuration.Alias) &&
                             (config.AccessKey == processor.Configuration.AccessKey) &&
                             (config.AwsGatewayToken == processor.Configuration.AwsGatewayToken) &&
                             (config.AuthToken == processor.Configuration.AuthToken) &&
                             (config.QueueUrl == processor.Configuration.QueueUrl) &&
                             (config.RedriveUrl == processor.Configuration.RedriveUrl) &&
                             (config.Region == processor.Configuration.Region) &&
                             (config.SecretKey == processor.Configuration.SecretKey));
                    if (found)
                    {
                        break;
                    }
                }

                if (!found)
                {
                    Logger.Debug($"Creating new queueprocessor for queue [{config.QueueUrl}], url [{config.RedriveUrl}], alias [{config.Alias}]");
                    var queueClient = queueClientFactory.CreateClient(config);
                    queueClient.Init();
                    var queueProcessor = queueProcessorFactory.CreateQueueProcessor();
                    queueProcessor.Init(queueClient, messageProcessorFactory, config);
                    toAdd.Add(queueProcessor);
                }
            }

            return(toAdd);
        }
コード例 #10
0
        public void ReadChanges(IConfigurationReader configurationReader,
                                List <IQueueProcessor> processors,
                                IQueueClientFactory queueClientFactory,
                                IMessageProcessorFactory messageProcessorFactory,
                                IQueueProcessorFactory queueProcessorFactory)
        {
            var configurations = configurationReader.ReadConfiguration();

            /*
             * First, create processors to add.
             */
            var toAdd = FindConfigsToAdd(configurations,
                                         processors,
                                         queueClientFactory,
                                         messageProcessorFactory,
                                         queueProcessorFactory);

            /*
             * Second, find processors to remove.
             */
            var toRemove = FindEntriesToRemove(configurations, processors);

            /*
             * Now remove those for removal and add the new ones.
             */

            foreach (var processor in toRemove)
            {
                Logger.Info($"Stopping queueprocessor for queue [{processor.Configuration.QueueUrl}], url [{processor.Configuration.RedriveUrl}], alias [{processor.Configuration.Alias}]");
                processor.Stop();
                processors.Remove(processor);
            }

            foreach (var processor in toAdd)
            {
                Logger.Info($"Starting new queueprocessor for queue [{processor.Configuration.QueueUrl}], url [{processor.Configuration.RedriveUrl}], alias [{processor.Configuration.Alias}]");
                processor.Start();
                processors.Add(processor);
            }
        }
コード例 #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);
        }
コード例 #12
0
        public QueueListener(CloudQueue queue,
                             CloudQueue poisonQueue,
                             ITriggerExecutor <CloudQueueMessage> triggerExecutor,
                             IWebJobsExceptionHandler exceptionHandler,
                             ILoggerFactory loggerFactory,
                             SharedQueueWatcher sharedWatcher,
                             QueuesOptions queueOptions,
                             IQueueProcessorFactory queueProcessorFactory,
                             TimeSpan?maxPollingInterval = null)
        {
            if (queueOptions == null)
            {
                throw new ArgumentNullException(nameof(queueOptions));
            }

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

            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;

            // 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 = CreateQueueProcessor(_queue, _poisonQueue, loggerFactory, queueProcessorFactory, _queueOptions, 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);
        }
コード例 #13
0
        internal static QueueProcessor CreateQueueProcessor(CloudQueue queue, CloudQueue poisonQueue, ILoggerFactory loggerFactory, IQueueProcessorFactory queueProcessorFactory,
                                                            QueuesOptions queuesOptions, EventHandler <PoisonMessageEventArgs> poisonQueueMessageAddedHandler)
        {
            QueueProcessorFactoryContext context = new QueueProcessorFactoryContext(queue, loggerFactory, queuesOptions, poisonQueue);

            QueueProcessor queueProcessor = null;

            if (HostQueueNames.IsHostQueue(queue.Name) &&
                string.Compare(queue.Uri.Host, "localhost", StringComparison.OrdinalIgnoreCase) != 0)
            {
                // We only delegate to the processor factory for application queues,
                // not our built in control queues
                // We bypass this check for local testing though
                queueProcessor = new QueueProcessor(context);
            }
            else
            {
                queueProcessor = queueProcessorFactory.Create(context);
            }

            if (poisonQueueMessageAddedHandler != null)
            {
                queueProcessor.MessageAddedToPoisonQueue += poisonQueueMessageAddedHandler;
            }

            return(queueProcessor);
        }
コード例 #14
0
        public QueueListener(QueueClient queue,
                             QueueClient poisonQueue,
                             ITriggerExecutor <QueueMessage> triggerExecutor,
                             IWebJobsExceptionHandler exceptionHandler,
                             ILoggerFactory loggerFactory,
                             SharedQueueWatcher sharedWatcher,
                             QueuesOptions queueOptions,
                             IQueueProcessorFactory queueProcessorFactory,
                             FunctionDescriptor functionDescriptor,
                             string functionId           = null,
                             TimeSpan?maxPollingInterval = null)
        {
            if (queueOptions == null)
            {
                throw new ArgumentNullException(nameof(queueOptions));
            }

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

            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;
            }

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

            _queueProcessor = CreateQueueProcessor(_queue, _poisonQueue, loggerFactory, queueProcessorFactory, _queueOptions, poisonMessageEventHandler);

            TimeSpan maximumInterval = _queueProcessor.MaxPollingInterval;

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

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

            _scaleMonitorDescriptor          = new ScaleMonitorDescriptor($"{_functionId}-QueueTrigger-{_queue.Name}".ToLower(CultureInfo.InvariantCulture));
            _shutdownCancellationTokenSource = new CancellationTokenSource();
        }