public BlobTriggerAttributeBindingProvider(
            INameResolver nameResolver,
            BlobServiceClientProvider blobServiceClientProvider,
            QueueServiceClientProvider queueServiceClientProvider,
            IHostIdProvider hostIdProvider,
            IOptions <BlobsOptions> blobsOptions,
            IWebJobsExceptionHandler exceptionHandler,
            IContextSetter <IBlobWrittenWatcher> blobWrittenWatcherSetter,
            BlobTriggerQueueWriterFactory blobTriggerQueueWriterFactory,
            ISharedContextProvider sharedContextProvider,
            IHostSingletonManager singletonManager,
            ILoggerFactory loggerFactory,
            ConcurrencyManager concurrencyManager)
        {
            _blobServiceClientProvider  = blobServiceClientProvider ?? throw new ArgumentNullException(nameof(blobServiceClientProvider));
            _queueServiceClientProvider = queueServiceClientProvider ?? throw new ArgumentNullException(nameof(queueServiceClientProvider));
            _hostIdProvider             = hostIdProvider ?? throw new ArgumentNullException(nameof(hostIdProvider));
            _blobsOptions                  = (blobsOptions ?? throw new ArgumentNullException(nameof(blobsOptions))).Value;
            _exceptionHandler              = exceptionHandler ?? throw new ArgumentNullException(nameof(exceptionHandler));
            _blobWrittenWatcherSetter      = blobWrittenWatcherSetter ?? throw new ArgumentNullException(nameof(blobWrittenWatcherSetter));
            _blobTriggerQueueWriterFactory = blobTriggerQueueWriterFactory ?? throw new ArgumentNullException(nameof(blobTriggerQueueWriterFactory));
            _sharedContextProvider         = sharedContextProvider ?? throw new ArgumentNullException(nameof(sharedContextProvider));
            _singletonManager              = singletonManager ?? throw new ArgumentNullException(nameof(singletonManager));
            _concurrencyManager            = concurrencyManager ?? throw new ArgumentNullException(nameof(concurrencyManager));

            _nameResolver  = nameResolver;
            _loggerFactory = loggerFactory;
            _logger        = loggerFactory.CreateLogger <BlobTriggerAttributeBindingProvider>();
        }
        public QueueListenerFactory(
            QueueServiceClient queueServiceClient,
            QueueClient queue,
            QueuesOptions queueOptions,
            IWebJobsExceptionHandler exceptionHandler,
            SharedQueueWatcher messageEnqueuedWatcherSetter,
            ILoggerFactory loggerFactory,
            ITriggeredFunctionExecutor executor,
            IQueueProcessorFactory queueProcessorFactory,
            QueueCausalityManager queueCausalityManager,
            FunctionDescriptor descriptor,
            ConcurrencyManager concurrencyManager
            )
        {
            _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));
            _concurrencyManager           = concurrencyManager ?? throw new ArgumentNullException(nameof(concurrencyManager));
            _queueCausalityManager        = queueCausalityManager ?? throw new ArgumentNullException(nameof(queueCausalityManager));

            _poisonQueue           = CreatePoisonQueueReference(queueServiceClient, queue.Name);
            _loggerFactory         = loggerFactory;
            _queueProcessorFactory = queueProcessorFactory;
        }
Example #3
0
        private void SetFunctionCurrentConcurrency(ConcurrencyManager concurrencyManager, string functionId, int concurrency)
        {
            var concurrencyStatus = concurrencyManager.GetStatus(functionId);
            var propertyInfo      = typeof(ConcurrencyStatus).GetProperty("CurrentConcurrency", BindingFlags.Instance | BindingFlags.Public);

            propertyInfo.SetValue(concurrencyStatus, concurrency);
        }
Example #4
0
        public void ConcurrencyUpdateManager_UpdatesProcessorConcurrency()
        {
            var concurrencyOptions = new OptionsWrapper <ConcurrencyOptions>(new ConcurrencyOptions {
                DynamicConcurrencyEnabled = true
            });
            var concurrencyManager = new ConcurrencyManager(concurrencyOptions, _loggerFactory, _mockConcurrencyThrottleManager.Object);

            _mockConcurrencyThrottleManager.Setup(p => p.GetStatus()).Returns(new ConcurrencyThrottleAggregateStatus {
                State = ThrottleState.Disabled
            });
            ServiceBusProcessor     processor        = _client.CreateProcessor(_entityPath);
            Lazy <MessageProcessor> messageProcessor = new Lazy <MessageProcessor>(() => new MessageProcessor(processor));
            ILogger logger = _loggerFactory.CreateLogger("test");

            ServiceBusListener.ConcurrencyUpdateManager concurrencyUpdateManager = new ServiceBusListener.ConcurrencyUpdateManager(concurrencyManager, messageProcessor, null, false, _functionId, logger);

            // when no messages are being processed, concurrency is not adjusted
            Assert.AreEqual(1, processor.MaxConcurrentCalls);
            SetFunctionCurrentConcurrency(concurrencyManager, _functionId, 10);
            concurrencyUpdateManager.UpdateConcurrency();
            Assert.AreEqual(1, processor.MaxConcurrentCalls);

            // ensure processor concurrency is adjusted up
            concurrencyUpdateManager.MessageProcessed();
            concurrencyUpdateManager.UpdateConcurrency();
            Assert.AreEqual(10, processor.MaxConcurrentCalls);

            // ensure processor concurrency is adjusted down
            SetFunctionCurrentConcurrency(concurrencyManager, _functionId, 5);
            concurrencyUpdateManager.MessageProcessed();
            concurrencyUpdateManager.UpdateConcurrency();
            Assert.AreEqual(5, processor.MaxConcurrentCalls);
        }
Example #5
0
        public void CanReadWrittenDateRecord()
        {
            var tableFile = RandomFilename;
            var schema    = new Schema();

            schema.AddDateField("field");
            _tableInfo = new TableInfo(tableFile, schema);

            _recordFile = new RecordFile(_tableInfo, _transaction);
            _recordFile.MoveToRID(new RID(0, 0));
            _recordFile.SetDate("field", new DateTime(2020, 1, 1));
            _recordFile.Close();

            _transaction.Commit();

            var cm    = new ConcurrencyManager();
            var newTr = new Transaction(_dispatcher, _bufferManager, cm, _fileManager, _logManager);

            var rf = new RecordFile(_tableInfo, newTr);

            rf.MoveToRID(new RID(0, 0));
            var value = rf.GetDate("field");

            Assert.AreEqual(new DateTime(2020, 1, 1), value);
        }
        public QueueTriggerBinding(string parameterName,
                                   QueueServiceClient queueServiceClient,
                                   QueueClient queue,
                                   ITriggerDataArgumentBinding <QueueMessage> argumentBinding,
                                   QueuesOptions queueOptions,
                                   IWebJobsExceptionHandler exceptionHandler,
                                   SharedQueueWatcher messageEnqueuedWatcherSetter,
                                   ILoggerFactory loggerFactory,
                                   IQueueProcessorFactory queueProcessorFactory,
                                   QueueCausalityManager queueCausalityManager,
                                   ConcurrencyManager concurrencyManager)
        {
            _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));
            _concurrencyManager           = concurrencyManager ?? throw new ArgumentNullException(nameof(concurrencyManager));

            _parameterName         = parameterName;
            _loggerFactory         = loggerFactory;
            _queueProcessorFactory = queueProcessorFactory;
            _converter             = CreateConverter(_queue);
            _logger = loggerFactory.CreateLogger <QueueTriggerBinding>();
        }
Example #7
0
        public QueueTriggerAttributeBindingProvider(INameResolver nameResolver,
                                                    QueueServiceClientProvider queueServiceClientProvider,
                                                    IOptions <QueuesOptions> queueOptions,
                                                    IWebJobsExceptionHandler exceptionHandler,
                                                    SharedQueueWatcher messageEnqueuedWatcherSetter,
                                                    ILoggerFactory loggerFactory,
                                                    IQueueProcessorFactory queueProcessorFactory,
                                                    QueueCausalityManager queueCausalityManager,
                                                    ConcurrencyManager concurrencyManager)
        {
            _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));
            _concurrencyManager           = concurrencyManager ?? throw new ArgumentNullException(nameof(concurrencyManager));

            _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.
        }
        public void Setup()
        {
            _mockExecutor = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict);
            _client       = new ServiceBusClient(_testConnection);
            ServiceBusProcessorOptions processorOptions = new ServiceBusProcessorOptions();
            ServiceBusProcessor        messageProcessor = _client.CreateProcessor(_entityPath);
            ServiceBusReceiver         receiver         = _client.CreateReceiver(_entityPath);

            _mockMessageProcessor = new Mock <MessageProcessor>(MockBehavior.Strict, messageProcessor);
            var configuration = ConfigurationUtilities.CreateConfiguration(new KeyValuePair <string, string>(_connection, _testConnection));

            _serviceBusOptions = new ServiceBusOptions();
            _mockProvider      = new Mock <MessagingProvider>(new OptionsWrapper <ServiceBusOptions>(_serviceBusOptions));
            _mockClientFactory = new Mock <ServiceBusClientFactory>(
                configuration,
                Mock.Of <AzureComponentFactory>(),
                _mockProvider.Object,
                new AzureEventSourceLogForwarder(new NullLoggerFactory()),
                new OptionsWrapper <ServiceBusOptions>(_serviceBusOptions));

            _mockProvider
            .Setup(p => p.CreateMessageProcessor(_client, _entityPath, It.IsAny <ServiceBusProcessorOptions>()))
            .Returns(_mockMessageProcessor.Object);

            _mockProvider
            .Setup(p => p.CreateClient(_testConnection, It.IsAny <ServiceBusClientOptions>()))
            .Returns(_client);

            _loggerFactory  = new LoggerFactory();
            _loggerProvider = new TestLoggerProvider();
            _loggerFactory.AddProvider(_loggerProvider);

            var concurrencyOptions             = new OptionsWrapper <ConcurrencyOptions>(new ConcurrencyOptions());
            var mockConcurrencyThrottleManager = new Mock <IConcurrencyThrottleManager>(MockBehavior.Strict);
            var concurrencyManager             = new ConcurrencyManager(concurrencyOptions, _loggerFactory, mockConcurrencyThrottleManager.Object);

            _listener = new ServiceBusListener(
                _functionId,
                ServiceBusEntityType.Queue,
                _entityPath,
                false,
                _serviceBusOptions.AutoCompleteMessages,
                _mockExecutor.Object,
                _serviceBusOptions,
                _connection,
                _mockProvider.Object,
                _loggerFactory,
                false,
                _mockClientFactory.Object,
                concurrencyManager);

            _scaleMonitor = (ServiceBusScaleMonitor)_listener.GetMonitor();
        }
Example #9
0
        public ServiceBusListenerTests()
        {
            _mockExecutor = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict);

            _client = new ServiceBusClient(_testConnection);
            ServiceBusProcessor processor = _client.CreateProcessor(_entityPath);
            ServiceBusReceiver  receiver  = _client.CreateReceiver(_entityPath);
            var configuration             = ConfigurationUtilities.CreateConfiguration(new KeyValuePair <string, string>("connection", _testConnection));

            ServiceBusOptions config = new ServiceBusOptions
            {
                ProcessErrorAsync = ExceptionReceivedHandler
            };

            _mockMessageProcessor = new Mock <MessageProcessor>(MockBehavior.Strict, processor);

            _mockMessagingProvider = new Mock <MessagingProvider>(new OptionsWrapper <ServiceBusOptions>(config));
            _mockClientFactory     = new Mock <ServiceBusClientFactory>(configuration, Mock.Of <AzureComponentFactory>(), _mockMessagingProvider.Object, new AzureEventSourceLogForwarder(new NullLoggerFactory()), new OptionsWrapper <ServiceBusOptions>(new ServiceBusOptions()));
            _mockMessagingProvider
            .Setup(p => p.CreateMessageProcessor(It.IsAny <ServiceBusClient>(), _entityPath, It.IsAny <ServiceBusProcessorOptions>()))
            .Returns(_mockMessageProcessor.Object);

            _mockMessagingProvider
            .Setup(p => p.CreateBatchMessageReceiver(It.IsAny <ServiceBusClient>(), _entityPath, default))
            .Returns(receiver);

            _loggerFactory  = new LoggerFactory();
            _loggerProvider = new TestLoggerProvider();
            _loggerFactory.AddProvider(_loggerProvider);

            var concurrencyOptions = new OptionsWrapper <ConcurrencyOptions>(new ConcurrencyOptions());

            _mockConcurrencyThrottleManager = new Mock <IConcurrencyThrottleManager>(MockBehavior.Strict);
            var concurrencyManager = new ConcurrencyManager(concurrencyOptions, _loggerFactory, _mockConcurrencyThrottleManager.Object);

            _listener = new ServiceBusListener(
                _functionId,
                ServiceBusEntityType.Queue,
                _entityPath,
                false,
                config.AutoCompleteMessages,
                _mockExecutor.Object,
                config,
                "connection",
                _mockMessagingProvider.Object,
                _loggerFactory,
                false,
                _mockClientFactory.Object,
                concurrencyManager);
            _listener.Started = true;
        }
Example #10
0
            public ConcurrencyUpdateManager(ConcurrencyManager concurrencyManager, Lazy <MessageProcessor> messageProcessor, Lazy <SessionMessageProcessor> sessionMessageProcessor, bool sessionsEnabled, string functionId, ILogger logger)
            {
                _concurrencyManager      = concurrencyManager;
                _messageProcessor        = messageProcessor;
                _sessionMessageProcessor = sessionMessageProcessor;
                _isSessionsEnabled       = sessionsEnabled;
                _functionId = functionId;
                _logger     = logger;

                if (concurrencyManager.Enabled)
                {
                    _concurrencyUpdateTimer = new Timer(UpdateConcurrency, null, Timeout.Infinite, Timeout.Infinite);
                }
            }
Example #11
0
        public void CanNavigateThourghExistingRecordsMoreRecords()
        {
            var tableFile = RandomFilename;
            var schema    = new Schema();

            schema.AddIntField("field");
            _tableInfo = new TableInfo(tableFile, schema);

            _recordFile = new RecordFile(_tableInfo, _transaction);

            _recordFile.BeforeFirst();

            for (int i = 0; i < 12; ++i)
            {
                _recordFile.Insert();
                _recordFile.SetInt("field", i);
            }

            // And this folk would go to the next page
            _recordFile.Insert();
            _recordFile.SetInt("field", 123);

            _transaction.Commit();

            var cm    = new ConcurrencyManager();
            var newTr = new Transaction(_dispatcher, _bufferManager, cm, _fileManager, _logManager);

            var rf = new RecordFile(_tableInfo, newTr);

            rf.BeforeFirst();

            for (int i = 0; i < 12; ++i)
            {
                rf.Next();
                var value = rf.GetInt("field");
                Assert.AreEqual(i, value);
            }

            rf.Next();
            var lastValue = rf.GetInt("field");

            Assert.AreEqual(123, lastValue);

            var canMoveNext = rf.Next();

            Assert.IsFalse(canMoveNext);
        }
 /// <summary>
 /// Creates a new <see cref="ServiceBusExtensionConfigProvider"/> instance.
 /// </summary>
 ///// <param name="options">The <see cref="ServiceBusOptions"></see> to use./></param>
 public ServiceBusExtensionConfigProvider(
     IOptions <ServiceBusOptions> options,
     MessagingProvider messagingProvider,
     INameResolver nameResolver,
     ILoggerFactory loggerFactory,
     IConverterManager converterManager,
     ServiceBusClientFactory clientFactory,
     ConcurrencyManager concurrencyManager)
 {
     _options            = options.Value;
     _messagingProvider  = messagingProvider;
     _nameResolver       = nameResolver;
     _loggerFactory      = loggerFactory ?? NullLoggerFactory.Instance;
     _converterManager   = converterManager;
     _clientFactory      = clientFactory;
     _concurrencyManager = concurrencyManager;
 }
 public ServiceBusTriggerAttributeBindingProvider(
     INameResolver nameResolver,
     ServiceBusOptions options,
     MessagingProvider messagingProvider,
     ILoggerFactory loggerFactory,
     IConverterManager converterManager,
     ServiceBusClientFactory clientFactory,
     ConcurrencyManager concurrencyManager)
 {
     _nameResolver       = nameResolver ?? throw new ArgumentNullException(nameof(nameResolver));
     _options            = options ?? throw new ArgumentNullException(nameof(options));
     _messagingProvider  = messagingProvider ?? throw new ArgumentNullException(nameof(messagingProvider));
     _loggerFactory      = loggerFactory;
     _converterManager   = converterManager;
     _clientFactory      = clientFactory;
     _logger             = _loggerFactory.CreateLogger <ServiceBusTriggerAttributeBindingProvider>();
     _concurrencyManager = concurrencyManager;
 }
Example #14
0
        public ServiceBusTriggerAttributeBindingProviderTests()
        {
            var configuration = ConfigurationUtilities.CreateConfiguration(new KeyValuePair <string, string>(Constants.DefaultConnectionStringName, "defaultConnection"));

            Mock <INameResolver> mockResolver = new Mock <INameResolver>(MockBehavior.Strict);

            ServiceBusOptions options = new ServiceBusOptions();

            var loggerFactory                  = new LoggerFactory();
            var concurrencyOptions             = new OptionsWrapper <ConcurrencyOptions>(new ConcurrencyOptions());
            var mockConcurrencyThrottleManager = new Mock <IConcurrencyThrottleManager>(MockBehavior.Strict);
            var concurrencyManager             = new ConcurrencyManager(concurrencyOptions, loggerFactory, mockConcurrencyThrottleManager.Object);

            Mock <IConverterManager> convertManager = new Mock <IConverterManager>(MockBehavior.Default);
            var provider = new MessagingProvider(new OptionsWrapper <ServiceBusOptions>(options));
            var factory  = new ServiceBusClientFactory(configuration, new Mock <AzureComponentFactory>().Object, provider, new AzureEventSourceLogForwarder(new NullLoggerFactory()), new OptionsWrapper <ServiceBusOptions>(options));

            _provider = new ServiceBusTriggerAttributeBindingProvider(mockResolver.Object, options, provider, NullLoggerFactory.Instance, convertManager.Object, factory, concurrencyManager);
        }
        private ServiceBusListener CreateListener()
        {
            var concurrencyOptions             = new OptionsWrapper <ConcurrencyOptions>(new ConcurrencyOptions());
            var mockConcurrencyThrottleManager = new Mock <IConcurrencyThrottleManager>(MockBehavior.Strict);
            var concurrencyManager             = new ConcurrencyManager(concurrencyOptions, _loggerFactory, mockConcurrencyThrottleManager.Object);

            return(new ServiceBusListener(
                       _functionId,
                       ServiceBusEntityType.Queue,
                       _entityPath,
                       false,
                       _serviceBusOptions.AutoCompleteMessages,
                       _mockExecutor.Object,
                       _serviceBusOptions,
                       _connection,
                       _mockProvider.Object,
                       _loggerFactory,
                       false,
                       _mockClientFactory.Object,
                       concurrencyManager));
        }
        public void GetMessageReceiveCount_DynamicConcurrencyEnabled_ReturnsExpectedValue()
        {
            var concurrencyOptions = new ConcurrencyOptions
            {
                DynamicConcurrencyEnabled = true
            };
            var throttleStatus = new ConcurrencyThrottleAggregateStatus {
                State = ThrottleState.Disabled
            };
            var optionsWrapper = new OptionsWrapper <ConcurrencyOptions>(concurrencyOptions);
            var mockConcurrencyThrottleManager = new Mock <IConcurrencyThrottleManager>(MockBehavior.Strict);

            mockConcurrencyThrottleManager.Setup(p => p.GetStatus()).Returns(() => throttleStatus);
            var concurrencyManager = new ConcurrencyManager(optionsWrapper, _loggerFactory, mockConcurrencyThrottleManager.Object);
            var localListener      = new QueueListener(_mockQueue.Object, null, _mockTriggerExecutor.Object, _mockExceptionDispatcher.Object, _loggerFactory, null, _queuesOptions, _mockQueueProcessor.Object, new FunctionDescriptor {
                Id = TestFunctionId
            }, concurrencyManager);

            int result = localListener.GetMessageReceiveCount();

            Assert.AreEqual(1, result);
        }
Example #17
0
 public BlobListenerFactory(IHostIdProvider hostIdProvider,
                            BlobsOptions blobsOptions,
                            IWebJobsExceptionHandler exceptionHandler,
                            IContextSetter <IBlobWrittenWatcher> blobWrittenWatcherSetter,
                            BlobTriggerQueueWriterFactory blobTriggerQueueWriterFactory,
                            ISharedContextProvider sharedContextProvider,
                            ILoggerFactory loggerFactory,
                            FunctionDescriptor functionDescriptor,
                            BlobServiceClient hostBlobServiceClient,
                            QueueServiceClient hostQueueServiceClient,
                            BlobServiceClient dataBlobServiceClient,
                            QueueServiceClient dataQueueServiceClient,
                            BlobContainerClient container,
                            IBlobPathSource input,
                            BlobTriggerSource triggerKind,
                            ITriggeredFunctionExecutor executor,
                            IHostSingletonManager singletonManager,
                            ConcurrencyManager concurrencyManager)
 {
     _hostIdProvider = hostIdProvider ?? throw new ArgumentNullException(nameof(hostIdProvider));
     _blobTriggerQueueWriterFactory = blobTriggerQueueWriterFactory ?? throw new ArgumentNullException(nameof(blobTriggerQueueWriterFactory));
     _blobsOptions             = blobsOptions ?? throw new ArgumentNullException(nameof(blobsOptions));
     _exceptionHandler         = exceptionHandler ?? throw new ArgumentNullException(nameof(exceptionHandler));
     _blobWrittenWatcherSetter = blobWrittenWatcherSetter ?? throw new ArgumentNullException(nameof(blobWrittenWatcherSetter));
     _sharedContextProvider    = sharedContextProvider ?? throw new ArgumentNullException(nameof(sharedContextProvider));
     _functionDescriptor       = functionDescriptor ?? throw new ArgumentNullException(nameof(functionDescriptor));
     _loggerFactory            = loggerFactory;
     _hostBlobServiceClient    = hostBlobServiceClient ?? throw new ArgumentNullException(nameof(hostBlobServiceClient));
     _hostQueueServiceClient   = hostQueueServiceClient ?? throw new ArgumentNullException(nameof(hostQueueServiceClient));
     _dataBlobServiceClient    = dataBlobServiceClient ?? throw new ArgumentNullException(nameof(dataBlobServiceClient));
     _dataQueueServiceClient   = dataQueueServiceClient ?? throw new ArgumentNullException(nameof(dataQueueServiceClient));
     _container          = container ?? throw new ArgumentNullException(nameof(container));
     _input              = input ?? throw new ArgumentNullException(nameof(input));
     _blobTriggerSource  = triggerKind;
     _executor           = executor ?? throw new ArgumentNullException(nameof(executor));
     _singletonManager   = singletonManager ?? throw new ArgumentNullException(nameof(singletonManager));
     _concurrencyManager = concurrencyManager ?? throw new ArgumentNullException(nameof(concurrencyManager));
 }
Example #18
0
        public BlobTriggerBinding(ParameterInfo parameter,
                                  BlobServiceClient hostBlobServiceClient,
                                  QueueServiceClient hostQueueServiceClient,
                                  BlobServiceClient dataBlobServiceClient,
                                  QueueServiceClient dataQueueServiceClient,
                                  IBlobPathSource path,
                                  BlobTriggerSource blobTriggerSource,
                                  IHostIdProvider hostIdProvider,
                                  BlobsOptions blobsOptions,
                                  IWebJobsExceptionHandler exceptionHandler,
                                  IContextSetter <IBlobWrittenWatcher> blobWrittenWatcherSetter,
                                  BlobTriggerQueueWriterFactory blobTriggerQueueWriterFactory,
                                  ISharedContextProvider sharedContextProvider,
                                  IHostSingletonManager singletonManager,
                                  ILoggerFactory loggerFactory,
                                  ConcurrencyManager concurrencyManager)
        {
            _parameter              = parameter ?? throw new ArgumentNullException(nameof(parameter));
            _hostBlobServiceClient  = hostBlobServiceClient ?? throw new ArgumentNullException(nameof(hostBlobServiceClient));
            _hostQueueServiceClient = hostQueueServiceClient ?? throw new ArgumentNullException(nameof(hostQueueServiceClient));
            _dataBlobServiceClient  = dataBlobServiceClient ?? throw new ArgumentNullException(nameof(dataBlobServiceClient));
            _dataQueueServiceClient = dataQueueServiceClient ?? throw new ArgumentNullException(nameof(dataQueueServiceClient));

            _accountName                   = _dataBlobServiceClient.AccountName;
            _path                          = path ?? throw new ArgumentNullException(nameof(path));
            _blobTriggerSource             = blobTriggerSource;
            _hostIdProvider                = hostIdProvider ?? throw new ArgumentNullException(nameof(hostIdProvider));
            _blobsOptions                  = blobsOptions ?? throw new ArgumentNullException(nameof(blobsOptions));
            _exceptionHandler              = exceptionHandler ?? throw new ArgumentNullException(nameof(exceptionHandler));
            _blobWrittenWatcherSetter      = blobWrittenWatcherSetter ?? throw new ArgumentNullException(nameof(blobWrittenWatcherSetter));
            _blobTriggerQueueWriterFactory = blobTriggerQueueWriterFactory ?? throw new ArgumentNullException(nameof(blobTriggerQueueWriterFactory));
            _sharedContextProvider         = sharedContextProvider ?? throw new ArgumentNullException(nameof(sharedContextProvider));
            _singletonManager              = singletonManager ?? throw new ArgumentNullException(nameof(singletonManager));
            _concurrencyManager            = concurrencyManager ?? throw new ArgumentNullException(nameof(concurrencyManager));
            _loggerFactory                 = loggerFactory;
            _converter                     = CreateConverter(_dataBlobServiceClient);
            _bindingDataContract           = CreateBindingDataContract(path);
        }
 public SharedBlobQueueListenerFactory(
     QueueServiceClient hostQueueServiceClient,
     SharedQueueWatcher sharedQueueWatcher,
     QueueClient hostBlobTriggerQueue,
     BlobsOptions blobsOptions,
     IWebJobsExceptionHandler exceptionHandler,
     ILoggerFactory loggerFactory,
     IBlobWrittenWatcher blobWrittenWatcher,
     FunctionDescriptor functionDescriptor,
     BlobTriggerSource blobTriggerSource,
     ConcurrencyManager concurrencyManager)
 {
     _hostQueueServiceClient = hostQueueServiceClient ?? throw new ArgumentNullException(nameof(hostQueueServiceClient));
     _sharedQueueWatcher     = sharedQueueWatcher ?? throw new ArgumentNullException(nameof(sharedQueueWatcher));
     _hostBlobTriggerQueue   = hostBlobTriggerQueue ?? throw new ArgumentNullException(nameof(hostBlobTriggerQueue));
     _blobsOptions           = blobsOptions ?? throw new ArgumentNullException(nameof(blobsOptions));
     _exceptionHandler       = exceptionHandler ?? throw new ArgumentNullException(nameof(exceptionHandler));
     _loggerFactory          = loggerFactory;
     _blobWrittenWatcher     = blobWrittenWatcher;
     _functionDescriptor     = functionDescriptor;
     _blobTriggerSource      = blobTriggerSource;
     _concurrencyManager     = concurrencyManager;
 }
Example #20
0
        public ServiceBusListener(
            string functionId,
            ServiceBusEntityType entityType,
            string entityPath,
            bool isSessionsEnabled,
            bool autoCompleteMessages,
            ITriggeredFunctionExecutor triggerExecutor,
            ServiceBusOptions options,
            string connection,
            MessagingProvider messagingProvider,
            ILoggerFactory loggerFactory,
            bool singleDispatch,
            ServiceBusClientFactory clientFactory,
            ConcurrencyManager concurrencyManager)
        {
            _entityPath              = entityPath;
            _isSessionsEnabled       = isSessionsEnabled;
            _autoCompleteMessages    = autoCompleteMessages;
            _triggerExecutor         = triggerExecutor;
            _cancellationTokenSource = new CancellationTokenSource();
            _logger     = loggerFactory.CreateLogger <ServiceBusListener>();
            _functionId = functionId;

            _client = new Lazy <ServiceBusClient>(
                () =>
                clientFactory.CreateClientFromSetting(connection));

            _batchReceiver = new Lazy <ServiceBusReceiver>(
                () => messagingProvider.CreateBatchMessageReceiver(
                    _client.Value,
                    _entityPath,
                    options.ToReceiverOptions()));

            _messageProcessor = new Lazy <MessageProcessor>(
                () =>
            {
                var processorOptions = options.ToProcessorOptions(_autoCompleteMessages, concurrencyManager.Enabled);
                return(messagingProvider.CreateMessageProcessor(_client.Value, _entityPath, processorOptions));
            });

            _sessionMessageProcessor = new Lazy <SessionMessageProcessor>(
                () =>
            {
                var sessionProcessorOptions = options.ToSessionProcessorOptions(_autoCompleteMessages, concurrencyManager.Enabled);
                return(messagingProvider.CreateSessionMessageProcessor(_client.Value, _entityPath, sessionProcessorOptions));
            });

            _scaleMonitor = new Lazy <ServiceBusScaleMonitor>(
                () => new ServiceBusScaleMonitor(
                    functionId,
                    entityType,
                    _entityPath,
                    connection,
                    _batchReceiver,
                    loggerFactory,
                    clientFactory));

            if (concurrencyManager.Enabled)
            {
                _concurrencyUpdateManager = new ConcurrencyUpdateManager(concurrencyManager, _messageProcessor, _sessionMessageProcessor, _isSessionsEnabled, _functionId, _logger);
            }

            _singleDispatch    = singleDispatch;
            _serviceBusOptions = options;

            _details = new Lazy <string>(() => $"namespace='{_client.Value?.FullyQualifiedNamespace}', enityPath='{_entityPath}', singleDispatch='{_singleDispatch}', " +
                                         $"isSessionsEnabled='{_isSessionsEnabled}', functionId='{_functionId}'");
        }
Example #21
0
        public QueueListener(QueueClient queue,
                             QueueClient poisonQueue,
                             ITriggerExecutor <QueueMessage> triggerExecutor,
                             IWebJobsExceptionHandler exceptionHandler,
                             ILoggerFactory loggerFactory,
                             SharedQueueWatcher sharedWatcher,
                             QueuesOptions queueOptions,
                             QueueProcessor queueProcessor,
                             FunctionDescriptor functionDescriptor,
                             ConcurrencyManager concurrencyManager = null,
                             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();

            _concurrencyManager = concurrencyManager;
        }
 protected override void Context()
 {
     _objectTypeResolver = A.Fake <IObjectTypeResolver>();
     sut = new ConcurrencyManager(_objectTypeResolver);
 }