public static ITriggerBindingProvider Create(INameResolver nameResolver,
            IStorageAccountProvider storageAccountProvider,
            IExtensionTypeLocator extensionTypeLocator,
            IHostIdProvider hostIdProvider,
            IQueueConfiguration queueConfiguration,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            IContextSetter<IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
            IContextSetter<IBlobWrittenWatcher> blobWrittenWatcherSetter,
            ISharedContextProvider sharedContextProvider,
            IExtensionRegistry extensions,
            TextWriter log)
        {
            List<ITriggerBindingProvider> innerProviders = new List<ITriggerBindingProvider>();
            innerProviders.Add(new QueueTriggerAttributeBindingProvider(nameResolver, storageAccountProvider,
                queueConfiguration, backgroundExceptionDispatcher, messageEnqueuedWatcherSetter,
                sharedContextProvider, log));
            innerProviders.Add(new BlobTriggerAttributeBindingProvider(nameResolver, storageAccountProvider,
                extensionTypeLocator, hostIdProvider, queueConfiguration, backgroundExceptionDispatcher,
                blobWrittenWatcherSetter, messageEnqueuedWatcherSetter, sharedContextProvider, log));

            // add any registered extension binding providers
            foreach (ITriggerBindingProvider provider in extensions.GetExtensions(typeof(ITriggerBindingProvider)))
            {
                innerProviders.Add(provider);
            }

            return new CompositeTriggerBindingProvider(innerProviders);
        }
        /// <summary>
        /// Registers a queue with the specified configuration.
        /// </summary>
        /// <param name="queueConfiguration">The queue configuration to register.</param>
        /// <returns>
        /// An instance of <see cref="IQueueContainer" /> that was registered.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">queueConfiguration</exception>
        public IQueueContainer Register(IQueueConfiguration queueConfiguration)
        {
            if (queueConfiguration == null)
            {
                throw new ArgumentNullException(nameof(queueConfiguration));
            }


            var queue = Load(queueConfiguration.Name);

            // update config
            var config = queue.Configuration;

            // copy values
            config.Description       = queueConfiguration.Description;
            config.PollTime          = queueConfiguration.PollTime;
            config.Priority          = queueConfiguration.Priority;
            config.ProcessTimeout    = queueConfiguration.ProcessTimeout;
            config.ResponseQueue     = queueConfiguration.ResponseQueue;
            config.RetryCount        = queueConfiguration.RetryCount;
            config.SubscriberFactory = queueConfiguration.SubscriberFactory;
            config.TimeoutPolicy     = queueConfiguration.TimeoutPolicy;
            config.WorkerCount       = queueConfiguration.WorkerCount;

            return(queue);
        }
Example #3
0
        public DispatchQueueTests()
        {
            _accountProviderMock = new Mock <IStorageAccountProvider>();
            IStorageAccountProvider accountProvider = new FakeStorageAccountProvider
            {
                StorageAccount = new FakeStorageAccount()
            };

            _accountProviderMock.Setup(m => m.TryGetAccountAsync(ConnectionStringNames.Storage, It.IsAny <CancellationToken>()))
            .Returns <string, CancellationToken>((name, cancel) => accountProvider.TryGetAccountAsync(name, cancel));

            _hostIdMock = new Mock <IHostIdProvider>();
            _hostIdMock.Setup(m => m.GetHostIdAsync(It.IsAny <CancellationToken>())).ReturnsAsync(HostId);

            _exceptionMock = new Mock <IWebJobsExceptionHandler>();

            _queueConfiguration = new FakeQueueConfiguration(accountProvider);

            _sharedContextProvider = new SharedContextProvider();

            _messageEnqueueSetterMock = new Mock <IContextSetter <IMessageEnqueuedWatcher> >();

            ILoggerFactory factory = new LoggerFactory();

            factory.AddProvider(_loggerProvider);

            _sharedQueue = new SharedQueueHandler(_accountProviderMock.Object,
                                                  _hostIdMock.Object,
                                                  _exceptionMock.Object,
                                                  factory,
                                                  _queueConfiguration,
                                                  _sharedContextProvider,
                                                  _messageEnqueueSetterMock.Object
                                                  );
        }
Example #4
0
 public RabbitMqClient(IResponseProcessor responseProcessor, IQueueConfiguration queueConfiguration, ILogger <RabbitMqClient <TResponseProcessor> > logger, IRabbitMqConnectionFactory rabbitMqConnectionFactory)
 {
     _responseProcessor         = responseProcessor ?? throw new ArgumentNullException(nameof(responseProcessor));
     _queueConfiguration        = queueConfiguration ?? throw new ArgumentNullException(nameof(queueConfiguration));
     _logger                    = logger ?? throw new ArgumentNullException(nameof(logger));
     _rabbitMqConnectionFactory = rabbitMqConnectionFactory ?? throw new ArgumentNullException(nameof(rabbitMqConnectionFactory));
 }
        public BlobTriggerAttributeBindingProvider(INameResolver nameResolver,
                                                   IStorageAccountProvider accountProvider,
                                                   IExtensionTypeLocator extensionTypeLocator,
                                                   IHostIdProvider hostIdProvider,
                                                   IQueueConfiguration queueConfiguration,
                                                   JobHostBlobsConfiguration blobsConfiguration,
                                                   IWebJobsExceptionHandler exceptionHandler,
                                                   IContextSetter <IBlobWrittenWatcher> blobWrittenWatcherSetter,
                                                   IContextSetter <IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
                                                   ISharedContextProvider sharedContextProvider,
                                                   SingletonManager singletonManager,
                                                   ILoggerFactory loggerFactory)
        {
            if (extensionTypeLocator == null)
            {
                throw new ArgumentNullException(nameof(extensionTypeLocator));
            }

            _accountProvider              = accountProvider ?? throw new ArgumentNullException(nameof(accountProvider));
            _hostIdProvider               = hostIdProvider ?? throw new ArgumentNullException(nameof(hostIdProvider));
            _queueConfiguration           = queueConfiguration ?? throw new ArgumentNullException(nameof(queueConfiguration));
            _blobsConfiguration           = blobsConfiguration ?? throw new ArgumentNullException(nameof(blobsConfiguration));
            _exceptionHandler             = exceptionHandler ?? throw new ArgumentNullException(nameof(exceptionHandler));
            _blobWrittenWatcherSetter     = blobWrittenWatcherSetter ?? throw new ArgumentNullException(nameof(blobWrittenWatcherSetter));
            _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter ?? throw new ArgumentNullException(nameof(messageEnqueuedWatcherSetter));
            _sharedContextProvider        = sharedContextProvider ?? throw new ArgumentNullException(nameof(sharedContextProvider));
            _singletonManager             = singletonManager ?? throw new ArgumentNullException(nameof(singletonManager));

            _nameResolver  = nameResolver;
            _loggerFactory = loggerFactory;
        }
Example #6
0
        public QueueConsumer(IQueueConfiguration queueConfiguration,
                             IQueueConnectionFactory connectionFactory,
                             IJsonSerializer serializer,
                             IValidationHelper validationHelper,
                             string consumerName)
        {
            _queueConfiguration = queueConfiguration ?? throw new ArgumentNullException(nameof(queueConfiguration));
            _connectionFactory  = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
            _serializer         = serializer ?? throw new ArgumentNullException(nameof(serializer));
            _validationHelper   = validationHelper ?? throw new ArgumentNullException(nameof(validationHelper));

            if (string.IsNullOrEmpty(consumerName))
            {
                throw new ArgumentNullException(nameof(consumerName));
            }

            _consumerName = consumerName;

            // verify that the queue configuration is valid
            if (!queueConfiguration.IsValid)
            {
                throw new ArgumentException("Queue Configuration is not valid", nameof(queueConfiguration));
            }

            // retrieve the specific queues configuration
            _consumerConfig = queueConfiguration.Consumers?.FirstOrDefault(c => c.Name == _consumerName);

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

            this._performanceLoggingMethodName = $"{consumerName}.Run";
        }
Example #7
0
        public static ITriggerBindingProvider Create(INameResolver nameResolver,
                                                     IStorageAccountProvider storageAccountProvider,
                                                     IExtensionTypeLocator extensionTypeLocator,
                                                     IHostIdProvider hostIdProvider,
                                                     IQueueConfiguration queueConfiguration,
                                                     JobHostBlobsConfiguration blobsConfiguration,
                                                     IWebJobsExceptionHandler exceptionHandler,
                                                     IContextSetter <IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
                                                     IContextSetter <IBlobWrittenWatcher> blobWrittenWatcherSetter,
                                                     ISharedContextProvider sharedContextProvider,
                                                     IExtensionRegistry extensions,
                                                     SingletonManager singletonManager,
                                                     TraceWriter trace,
                                                     ILoggerFactory loggerFactory)
        {
            List <ITriggerBindingProvider> innerProviders = new List <ITriggerBindingProvider>();

            innerProviders.Add(new QueueTriggerAttributeBindingProvider(nameResolver, storageAccountProvider,
                                                                        queueConfiguration, exceptionHandler, messageEnqueuedWatcherSetter,
                                                                        sharedContextProvider, trace, loggerFactory));
            innerProviders.Add(new BlobTriggerAttributeBindingProvider(nameResolver, storageAccountProvider, extensionTypeLocator,
                                                                       hostIdProvider, queueConfiguration, blobsConfiguration, exceptionHandler, blobWrittenWatcherSetter,
                                                                       messageEnqueuedWatcherSetter, sharedContextProvider, singletonManager, trace, loggerFactory));

            // add any registered extension binding providers
            foreach (ITriggerBindingProvider provider in extensions.GetExtensions(typeof(ITriggerBindingProvider)))
            {
                innerProviders.Add(provider);
            }

            return(new CompositeTriggerBindingProvider(innerProviders));
        }
Example #8
0
 public BlobListenerFactory(IHostIdProvider hostIdProvider,
                            IQueueConfiguration queueConfiguration,
                            JobHostBlobsConfiguration blobsConfiguration,
                            IWebJobsExceptionHandler exceptionHandler,
                            IContextSetter <IBlobWrittenWatcher> blobWrittenWatcherSetter,
                            IContextSetter <IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
                            ISharedContextProvider sharedContextProvider,
                            ILoggerFactory loggerFactory,
                            string functionId,
                            IStorageAccount hostAccount,
                            IStorageAccount dataAccount,
                            IStorageBlobContainer container,
                            IBlobPathSource input,
                            ITriggeredFunctionExecutor executor,
                            SingletonManager singletonManager)
 {
     _hostIdProvider               = hostIdProvider ?? throw new ArgumentNullException(nameof(hostIdProvider));
     _queueConfiguration           = queueConfiguration ?? throw new ArgumentNullException(nameof(queueConfiguration));
     _blobsConfiguration           = blobsConfiguration ?? throw new ArgumentNullException(nameof(blobsConfiguration));
     _exceptionHandler             = exceptionHandler ?? throw new ArgumentNullException(nameof(exceptionHandler));
     _blobWrittenWatcherSetter     = blobWrittenWatcherSetter ?? throw new ArgumentNullException(nameof(blobWrittenWatcherSetter));
     _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter ?? throw new ArgumentNullException(nameof(messageEnqueuedWatcherSetter));
     _sharedContextProvider        = sharedContextProvider ?? throw new ArgumentNullException(nameof(sharedContextProvider));
     _loggerFactory    = loggerFactory;
     _functionId       = functionId;
     _hostAccount      = hostAccount ?? throw new ArgumentNullException(nameof(hostAccount));
     _dataAccount      = dataAccount ?? throw new ArgumentNullException(nameof(dataAccount));
     _container        = container ?? throw new ArgumentNullException(nameof(container));
     _input            = input ?? throw new ArgumentNullException(nameof(input));
     _executor         = executor ?? throw new ArgumentNullException(nameof(executor));
     _singletonManager = singletonManager ?? throw new ArgumentNullException(nameof(singletonManager));
 }
Example #9
0
        public QueuePublisher(IQueueConfiguration queueConfiguration,
                              IQueueConnectionFactory connectionFactory,
                              IJsonSerializer serializer,
                              IValidationHelper validationHelper,
                              string publisherName,
                              CancellationToken cancellationToken)
        {
            if (queueConfiguration == null)
            {
                throw new ArgumentNullException(nameof(queueConfiguration));
            }

            _connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
            _publisherName     = publisherName ?? throw new ArgumentNullException(nameof(publisherName));
            _serializer        = serializer ?? throw new ArgumentNullException(nameof(serializer));
            _validationHelper  = validationHelper ?? throw new ArgumentNullException(nameof(validationHelper));
            _cancellationToken = cancellationToken;

            // verify that the queue configuration is valid
            if (!queueConfiguration.IsValid)
            {
                throw new ArgumentException("Queue Configuration is not valid", nameof(queueConfiguration));
            }

            // retrieve the specific queues configuration
            _publisherConfig = queueConfiguration.Publishers?.FirstOrDefault(c => c.Name == _publisherName);

            if (_publisherConfig == null)
            {
                throw new ArgumentNullException(nameof(_publisherConfig));
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageProcessor"/> class.
 /// </summary>
 /// <param name="service">The parent message service.</param>
 /// <param name="container">The queue container to process.</param>
 public MessageProcessor(IMessageService service, IQueueContainer container)
 {
     _workers       = new Lazy <IList <IMessageWorker> >(CreateWorkers);
     _service       = service;
     _container     = container;
     _configuration = container.Configuration;
 }
Example #11
0
        public QueueConsumer(IQueueConfiguration queueConfiguration,
                             IQueueConnectionFactory connectionFactory,
                             IJsonSerializer serializer,
                             string consumerName,
                             CancellationToken cancellationToken)
        {
            _queueConfiguration = queueConfiguration ?? throw new ArgumentNullException(nameof(queueConfiguration));
            _connectionFactory  = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
            _consumerName       = consumerName ?? throw new ArgumentNullException(nameof(consumerName));
            _serializer         = serializer ?? throw new ArgumentNullException(nameof(serializer));

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

            _cancellationToken = cancellationToken;

            // retrieve the specific queues configuration
            _queueConfig = queueConfiguration.Publishers.Cast <QueueConfig>().Where(p => p.Name == _consumerName).FirstOrDefault() as IQueueConfig;

            if (_queueConfig == null)
            {
                throw new ArgumentNullException(nameof(_queueConfig));
            }
        }
Example #12
0
        public static IServiceCollection ConfigureServices(this IServiceCollection serviceCollection, IConfiguration configuration)
        {
            IQueueConfiguration queueConfig = RabbitMqDefaultConfigLoader.SetDefaults(new RabbitMqQueueConfiguration());

            configuration.Bind(queueConfig);
            serviceCollection.AddTransient <IQueueConfiguration>(x => queueConfig);

            IStoreConfiguration storeConfig = AdaptationStoreConfigLoader.SetDefaults(new AdaptationStoreConfiguration());

            configuration.Bind(storeConfig);
            serviceCollection.AddTransient <IStoreConfiguration>(x => storeConfig);

            IProcessingConfiguration processingConfig = IcapProcessingConfigLoader.SetDefaults(new IcapProcessingConfiguration());

            configuration.Bind(processingConfig);
            serviceCollection.AddTransient <IProcessingConfiguration>(x => processingConfig);

            ICloudSdkConfiguration versionConfiguration = CloudSdkConfigLoader.SetDefaults(new CloudSdkConfiguration());

            configuration.Bind(versionConfiguration);
            serviceCollection.AddTransient <ICloudSdkConfiguration>(x => versionConfiguration);

            serviceCollection.AddTransient(typeof(IAdaptationServiceClient <>), typeof(RabbitMqClient <>));
            serviceCollection.AddTransient <IResponseProcessor, AdaptationOutcomeProcessor>();
            serviceCollection.AddTransient <IHttpService, HttpService.HttpService>();
            serviceCollection.AddSingleton <IRabbitMqConnectionFactory, RabbitMqConnectionFactory>();

            return(serviceCollection);
        }
Example #13
0
 public AgencyBanks(IComponentContext container)
 {
         this.iContainer = container;
         queueConfiguration = iContainer.Resolve<IQueueConfiguration>();
         publisher = iContainer.Resolve<IExchangePublisher<Job>>();
         publisher.Declare(queueConfiguration.ResponseExchangeName);
 }
        internal static QueueProcessor CreateQueueProcessor(CloudQueue queue, CloudQueue poisonQueue, ILoggerFactory loggerFactory,
                                                            IQueueConfiguration queueConfig, EventHandler <PoisonMessageEventArgs> poisonQueueMessageAddedHandler)
        {
            QueueProcessorFactoryContext context = new QueueProcessorFactoryContext(queue, loggerFactory, queueConfig, 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 = queueConfig.QueueProcessorFactory.Create(context);
            }

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

            return(queueProcessor);
        }
 /// <summary>
 /// Constructs a new instance
 /// </summary>
 /// <param name="queue">The <see cref="CloudQueue"/> the <see cref="QueueProcessor"/> will operate on.</param>
 /// <param name="log">The log to write to.</param>
 /// <param name="queueConfiguration">The queue configuration.</param>
 /// <param name="poisonQueue">The queue to move messages to when unable to process a message after the maximum dequeue count has been exceeded. May be null.</param>
 internal QueueProcessorFactoryContext(CloudQueue queue, TextWriter log, IQueueConfiguration queueConfiguration, CloudQueue poisonQueue = null)
     : this(queue, log, poisonQueue)
 {
     BatchSize         = queueConfiguration.BatchSize;
     MaxDequeueCount   = queueConfiguration.MaxDequeueCount;
     NewBatchThreshold = queueConfiguration.NewBatchThreshold;
 }
 /// <summary>
 /// Constructs a new instance
 /// </summary>
 /// <param name="queue">The <see cref="CloudQueue"/> the <see cref="QueueProcessor"/> will operate on.</param>
 /// <param name="trace">The <see cref="TraceWriter"/> to write to.</param>
 /// <param name="queueConfiguration">The queue configuration.</param>
 /// <param name="poisonQueue">The queue to move messages to when unable to process a message after the maximum dequeue count has been exceeded. May be null.</param>
 internal QueueProcessorFactoryContext(CloudQueue queue, TraceWriter trace, IQueueConfiguration queueConfiguration, CloudQueue poisonQueue = null)
     : this(queue, trace, poisonQueue)
 {
     BatchSize = queueConfiguration.BatchSize;
     MaxDequeueCount = queueConfiguration.MaxDequeueCount;
     NewBatchThreshold = queueConfiguration.NewBatchThreshold;
 }
        public static ITriggerBindingProvider Create(INameResolver nameResolver,
                                                     IStorageAccountProvider storageAccountProvider,
                                                     IExtensionTypeLocator extensionTypeLocator,
                                                     IHostIdProvider hostIdProvider,
                                                     IQueueConfiguration queueConfiguration,
                                                     IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
                                                     IContextSetter <IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
                                                     IContextSetter <IBlobWrittenWatcher> blobWrittenWatcherSetter,
                                                     ISharedContextProvider sharedContextProvider,
                                                     IExtensionRegistry extensions,
                                                     TextWriter log)
        {
            List <ITriggerBindingProvider> innerProviders = new List <ITriggerBindingProvider>();

            innerProviders.Add(new QueueTriggerAttributeBindingProvider(nameResolver, storageAccountProvider,
                                                                        queueConfiguration, backgroundExceptionDispatcher, messageEnqueuedWatcherSetter,
                                                                        sharedContextProvider, log));
            innerProviders.Add(new BlobTriggerAttributeBindingProvider(nameResolver, storageAccountProvider,
                                                                       extensionTypeLocator, hostIdProvider, queueConfiguration, backgroundExceptionDispatcher,
                                                                       blobWrittenWatcherSetter, messageEnqueuedWatcherSetter, sharedContextProvider, log));

            // add any registered extension binding providers
            foreach (ITriggerBindingProvider provider in extensions.GetExtensions(typeof(ITriggerBindingProvider)))
            {
                innerProviders.Add(provider);
            }

            return(new CompositeTriggerBindingProvider(innerProviders));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageProcessor"/> class.
 /// </summary>
 /// <param name="service">The parent message service.</param>
 /// <param name="container">The queue container to process.</param>
 public MessageProcessor(IMessageService service, IQueueContainer container)
 {
     _workers = new Lazy<IList<IMessageWorker>>(CreateWorkers);
     _service = service;
     _container = container;
     _configuration = container.Configuration;
 }
        public static ITriggerBindingProvider Create(INameResolver nameResolver,
                                                     IStorageAccountProvider storageAccountProvider,
                                                     IServiceBusAccountProvider serviceBusAccountProvider,
                                                     IExtensionTypeLocator extensionTypeLocator,
                                                     IHostIdProvider hostIdProvider,
                                                     IQueueConfiguration queueConfiguration,
                                                     IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
                                                     IContextSetter <IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
                                                     IContextSetter <IBlobWrittenWatcher> blobWrittenWatcherSetter,
                                                     ISharedContextProvider sharedContextProvider,
                                                     TextWriter log)
        {
            List <ITriggerBindingProvider> innerProviders = new List <ITriggerBindingProvider>();

            innerProviders.Add(new QueueTriggerAttributeBindingProvider(nameResolver, storageAccountProvider,
                                                                        queueConfiguration, backgroundExceptionDispatcher, messageEnqueuedWatcherSetter,
                                                                        sharedContextProvider, log));
            innerProviders.Add(new BlobTriggerAttributeBindingProvider(nameResolver, storageAccountProvider,
                                                                       extensionTypeLocator, hostIdProvider, queueConfiguration, backgroundExceptionDispatcher,
                                                                       blobWrittenWatcherSetter, messageEnqueuedWatcherSetter, sharedContextProvider, log));

            Type serviceBusProviderType = ServiceBusExtensionTypeLoader.Get(
                "Microsoft.Azure.WebJobs.ServiceBus.Triggers.ServiceBusTriggerAttributeBindingProvider");

            if (serviceBusProviderType != null)
            {
                ITriggerBindingProvider serviceBusAttributeBindingProvider =
                    (ITriggerBindingProvider)Activator.CreateInstance(serviceBusProviderType, nameResolver,
                                                                      serviceBusAccountProvider);
                innerProviders.Add(serviceBusAttributeBindingProvider);
            }

            return(new CompositeTriggerBindingProvider(innerProviders));
        }
Example #20
0
        public QueuePublisher(IQueueConfiguration queueConfiguration,
                              IQueueConnectionFactory connectionFactory,
                              IJsonSerializer serializer,
                              string publisherName,
                              CancellationToken cancellationToken)
        {
            if (queueConfiguration == null)
            {
                throw new ArgumentNullException(nameof(queueConfiguration));
            }

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

            _connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
            _publisherName     = publisherName ?? throw new ArgumentNullException(nameof(publisherName));
            _serializer        = serializer ?? throw new ArgumentNullException(nameof(serializer));
            _cancellationToken = cancellationToken;

            // retrieve the specific queues configuration
            _publisherConfig = queueConfiguration.Publishers?.FirstOrDefault(c => c.Name == _publisherName);

            if (_publisherConfig == null)
            {
                throw new ArgumentNullException(nameof(_publisherConfig));
            }
        }
Example #21
0
 public BusProducer(IBusConnection connection, IQueueConfiguration config, ILogger logger = null)
 {
     _connection = connection;
     _logger     = logger;
     _config     = config;
     TryCreateChannel();
 }
        /// <summary>
        /// Adds a queue to the hierarchy.
        /// </summary>
        /// <param name="value">The queue to add.</param>
        /// <returns>The new <see cref="TreeNode"/> for the queue.</returns>
        private TreeNode AddQueue(IQueueConfiguration value)
        {
            this.hierarchy.BeginUpdate();
            try
            {
                // Check if the node already exists or not
                TreeNode queueNode;
                if (this.queues.ContainsKey(value.Name))
                {
                    queueNode = this.queues[value.Name];
                }
                else
                {
                    // Add the new node and store it
                    queueNode = this.AddNode(this.hierarchy.Nodes[0], value.Name, "queue", value);
                    this.queues.Add(value.Name, queueNode);
                }

                // If the node already exists, then the project will use it so this will be a safe call
                // The only time this method can be called twice if the actual queue configuration is set
                queueNode.Tag = value;
                return(queueNode);
            }
            finally
            {
                this.hierarchy.EndUpdate();
            }
        }
        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);
        }
Example #24
0
        public SharedBlobQueueListenerFactory(
            SharedQueueWatcher sharedQueueWatcher,
            IStorageQueueClient queueClient,
            IStorageQueue hostBlobTriggerQueue,
            IStorageBlobClient blobClient,
            IQueueConfiguration queueConfiguration,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            TextWriter log,
            IBlobWrittenWatcher blobWrittenWatcher)
        {
            if (sharedQueueWatcher == null)
            {
                throw new ArgumentNullException("sharedQueueWatcher");
            }

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

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

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

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

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

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

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

            _sharedQueueWatcher            = sharedQueueWatcher;
            _queueClient                   = queueClient;
            _hostBlobTriggerQueue          = hostBlobTriggerQueue;
            _blobClient                    = blobClient;
            _queueConfiguration            = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _log = log;
            _blobWrittenWatcher = blobWrittenWatcher;
        }
Example #25
0
        public void CreateQueueConfiguration()
        {
            var mockConfiguration = new Mock <IQueueConfiguration>();

            mockConfiguration.SetupAllProperties();

            defaultedConfiguration = RabbitMqDefaultConfigLoader.SetDefaults(mockConfiguration.Object);
        }
Example #26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IntegrationQueue" /> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="parentQueueSet">The parent queue set.</param>
        /// <remarks></remarks>
        public IntegrationQueue(string name, IQueueConfiguration configuration, IntegrationQueueSet parentQueueSet)
        {
            this.name           = name;
            this.configuration  = configuration;
            this.parentQueueSet = parentQueueSet;

            this.blockingQueueNames = new List <string>();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="IntegrationQueue" /> class.	
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="parentQueueSet">The parent queue set.</param>
        /// <remarks></remarks>
		public IntegrationQueue(string name, IQueueConfiguration configuration, IntegrationQueueSet parentQueueSet)
		{
			this.name = name;
            this.configuration = configuration;
            this.parentQueueSet = parentQueueSet;

            this.blockingQueueNames = new List<string>();
		}
Example #28
0
        public QueueTriggerBinding(string parameterName,
                                   IStorageQueue queue,
                                   ITriggerDataArgumentBinding <IStorageQueueMessage> argumentBinding,
                                   IQueueConfiguration queueConfiguration,
                                   IWebJobsExceptionHandler exceptionHandler,
                                   IContextSetter <IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
                                   ISharedContextProvider sharedContextProvider,
                                   TraceWriter trace,
                                   ILoggerFactory loggerFactory)
        {
            if (queue == null)
            {
                throw new ArgumentNullException("queue");
            }

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

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

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

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

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

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

            _parameterName                = parameterName;
            _queue                        = queue;
            _argumentBinding              = argumentBinding;
            _bindingDataContract          = CreateBindingDataContract(argumentBinding.BindingDataContract);
            _queueConfiguration           = queueConfiguration;
            _exceptionHandler             = exceptionHandler;
            _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter;
            _sharedContextProvider        = sharedContextProvider;
            _trace                        = trace;
            _loggerFactory                = loggerFactory;
            _converter                    = CreateConverter(queue);
        }
Example #29
0
 /// <summary>
 /// Constructs a new instance.
 /// </summary>
 /// <param name="queue">The <see cref="CloudQueue"/> the <see cref="QueueProcessor"/> will operate on.</param>
 /// <param name="trace">The <see cref="TraceWriter"/> to write to.</param>
 /// <param name="queueConfiguration">The queue configuration.</param>
 /// <param name="poisonQueue">The queue to move messages to when unable to process a message after the maximum dequeue count has been exceeded. May be null.</param>
 internal QueueProcessorFactoryContext(CloudQueue queue, TraceWriter trace, IQueueConfiguration queueConfiguration, CloudQueue poisonQueue = null)
     : this(queue, trace, poisonQueue)
 {
     BatchSize          = queueConfiguration.BatchSize;
     MaxDequeueCount    = queueConfiguration.MaxDequeueCount;
     NewBatchThreshold  = queueConfiguration.NewBatchThreshold;
     VisibilityTimeout  = queueConfiguration.VisibilityTimeout;
     MaxPollingInterval = queueConfiguration.MaxPollingInterval;
 }
Example #30
0
 public ServiceRunner(
     IQueueConfiguration queueConfiguration,
     IQueueConsumer<ExecuteBatchReportRequest> requestConsumer,
     IExchangePublisher<ExecuteBatchReportResponse> responsePublisher)
 {
     this.queueConfiguration = queueConfiguration;
     this.requestConsumer = requestConsumer;
     this.responsePublisher = responsePublisher;
 }
Example #31
0
 public ServiceRunner(
     IQueueConfiguration queueConfiguration,
     IQueueConsumer <CreateBatchAdjustmentLettersRequest> consumer,
     IExchangePublisher <CreateBatchAdjustmentLettersResponse> publisher)
 {
     this.queueConfiguration = queueConfiguration;
     this.consumer           = consumer;
     this.publisher          = publisher;
 }
Example #32
0
 public ServiceRunner(
     IQueueConfiguration queueConfiguration,
     IQueueConsumer<CreateBatchAdjustmentLettersRequest> consumer,
     IExchangePublisher<CreateBatchAdjustmentLettersResponse> publisher)
 {
     this.queueConfiguration = queueConfiguration;
     this.consumer = consumer;
     this.publisher = publisher;
 }
Example #33
0
 public ServiceRunner(
     IQueueConfiguration queueConfiguration,
     IQueueConsumer<ProcessValueInstructionFileAcknowledgmentRequest> createVifFileConsumer,
     IExchangePublisher<ProcessValueInstructionFileAcknowledgmentResponse> createVifFilePublisher)
 {
     this.queueConfiguration = queueConfiguration;
     this.createVifFileConsumer = createVifFileConsumer;
     this.createVifFilePublisher = createVifFilePublisher;
 }
Example #34
0
        private IQueueContainer CreateContainer(IQueueConfiguration configuration)
        {
            var collection = GetCollection(configuration.Name);
            var repository = new QueueRepository(collection);

            var queue = new QueueContainer(configuration, repository);

            return(queue);
        }
Example #35
0
 public ServiceRunner(
     IQueueConfiguration queueConfiguration,
     IQueueConsumer<MatchVoucherRequest> createVifFileConsumer,
     IExchangePublisher<MatchVoucherResponse> createVifFilePublisher)
 {
     this.queueConfiguration = queueConfiguration;
     this.createECLFileConsumer = createVifFileConsumer;
     this.createECLFilePublisher = createVifFilePublisher;    
 }
Example #36
0
 private static IQueue CreateQueueConfiguration(IQueueConfiguration queueConfiguration)
 {
     return(new Queue(
                name: queueConfiguration.Name,
                durable: queueConfiguration.Durable,
                exclusive: queueConfiguration.Exclusive,
                autoDelete: queueConfiguration.AutoDelete,
                arguments: queueConfiguration.Arguments));
 }
Example #37
0
 /// <summary>
 /// Adds the specified queue name.
 /// </summary>
 /// <param name="queueName">Name of the queue.</param>
 /// <param name="config">The config.</param>
 /// <remarks></remarks>
 public void Add(string queueName, IQueueConfiguration config)
 {
     lock (this)
     {
         if (!queueSet.ContainsKey(queueName))
         {
             queueSet.Add(queueName, new IntegrationQueue(queueName, config, this));
         }
     }
 }
 public void Add(string queueName, IQueueConfiguration config)
 {
     lock (this)
     {
         if (!queueSet.ContainsKey(queueName))
         {
             queueSet.Add(queueName, new IntegrationQueue(queueName, config, this));
         }
     }
 }
Example #39
0
        public void FindQueueNotFound()
        {
            Configuration       config      = new Configuration();
            IQueueConfiguration foundConfig = config.FindQueueConfiguration("Test Queue");

            Assert.IsNotNull(foundConfig);
            Assert.That(foundConfig, Is.InstanceOf <DefaultQueueConfiguration>());
            Assert.AreEqual("Test Queue", foundConfig.Name);
            Assert.AreEqual(QueueDuplicateHandlingMode.UseFirst, foundConfig.HandlingMode);
        }
Example #40
0
 public QueueThread(IProvideShutdownSignal shutdown,
                    IBusDataAccess dataAccess,
                    ILog <QueueThread> log,
                    IQueueWork queueWork,
                    IQueueConfiguration config)
     : base("Queue", 100, log, dataAccess, shutdown)
 {
     _queueWork           = queueWork;
     _queueWork.QueueName = config.QueueName;
 }
        public QueueTriggerBinding(string parameterName,
            IStorageQueue queue,
            ITriggerDataArgumentBinding<IStorageQueueMessage> argumentBinding,
            IQueueConfiguration queueConfiguration,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            IContextSetter<IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
            ISharedContextProvider sharedContextProvider,
            TextWriter log)
        {
            if (queue == null)
            {
                throw new ArgumentNullException("queue");
            }

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

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

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

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

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

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

            _parameterName = parameterName;
            _queue = queue;
            _argumentBinding = argumentBinding;
            _bindingDataContract = CreateBindingDataContract(argumentBinding);
            _queueConfiguration = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter;
            _sharedContextProvider = sharedContextProvider;
            _log = log;
            _converter = CreateConverter(queue);
        }
Example #42
0
 public ServiceRunner(
     IOutboundConfiguration outboundConfiguration,
     IQueueConfiguration queueConfiguration,
     IQueueConsumer<CreateImageExchangeFileRequest> createBatchImageExchangeFileConsumer,
     IExchangePublisher<CreateImageExchangeFileResponse> createBatchImageExchangeFilePublisher)
 {
     this.outboundConfiguration = outboundConfiguration;
     this.queueConfiguration = queueConfiguration;
     this.createBatchImageExchangeFileConsumer = createBatchImageExchangeFileConsumer;
     this.createBatchImageExchangeFilePublisher = createBatchImageExchangeFilePublisher;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="QueueContainer"/> class.
        /// </summary>
        /// <param name="configuration">The queue configuration.</param>
        /// <param name="repository">The storage repository.</param>
        /// <exception cref="System.ArgumentNullException">
        /// configuration
        /// or
        /// repository
        /// </exception>
        public QueueContainer(IQueueConfiguration configuration, IQueueRepository repository)
        {
            if (configuration == null)
                throw new ArgumentNullException("configuration");

            if (repository == null)
                throw new ArgumentNullException("repository");

            _name = configuration.Name;
            _configuration = configuration;
            _repository = repository;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="QueueContainer"/> class.
        /// </summary>
        /// <param name="configuration">The queue configuration.</param>
        /// <param name="repository">The storage repository.</param>
        /// <exception cref="System.ArgumentNullException">
        /// configuration
        /// or
        /// repository
        /// </exception>
        public QueueContainer(IQueueConfiguration configuration, IQueueRepository repository)
        {
            if (configuration == null)
                throw new ArgumentNullException(nameof(configuration));

            if (repository == null)
                throw new ArgumentNullException(nameof(repository));

            Name = configuration.Name;
            Configuration = configuration;
            Repository = repository;
        }
Example #45
0
        public QueueListenerFactory(IStorageQueue queue,
            IQueueConfiguration queueConfiguration,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            IContextSetter<IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
            ISharedContextProvider sharedContextProvider,
            TraceWriter trace,
            ITriggeredFunctionExecutor executor)
        {
            if (queue == null)
            {
                throw new ArgumentNullException("queue");
            }

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

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

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

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

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

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

            _queue = queue;
            _poisonQueue = CreatePoisonQueueReference(queue.ServiceClient, queue.Name);
            _queueConfiguration = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter;
            _sharedContextProvider = sharedContextProvider;
            _trace = trace;
            _executor = executor;
        }
        public HostMessageListenerFactory(IStorageQueue queue,
            IQueueConfiguration queueConfiguration,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            TextWriter log,
            IFunctionIndexLookup functionLookup,
            IFunctionInstanceLogger functionInstanceLogger,
            IFunctionExecutor executor)
        {
            if (queue == null)
            {
                throw new ArgumentNullException("queue");
            }

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

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

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

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

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

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

            _queue = queue;
            _queueConfiguration = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _log = log;
            _functionLookup = functionLookup;
            _functionInstanceLogger = functionInstanceLogger;
            _executor = executor;
        }
        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);
        }
Example #48
0
 public InternalBus(IMessageSender messageSender, IBusBootstrapper busBootstrapper, IDataReceiver dataReceiver, HandlingProcessorStandard handlingProcessorStandard, HandlingProcessorInfrastructure handlingProcessorInfrastructure, PersistenceSynchronizationProcessor networkProcessor, MessageTargetsHandler messageTargetsHandler, NetworkSender networkSender, IHeartbeatManager heartbeatManager, IQueueConfiguration queueConfiguration)
 {
     _messageSender = messageSender;
     _busBootstrapper = busBootstrapper;
     _dataReceiver = dataReceiver;
     _handlingProcessorStandard = handlingProcessorStandard;
     _handlingProcessorInfrastructure = handlingProcessorInfrastructure;
     _networkProcessor = networkProcessor;
     _messageTargetsHandler = messageTargetsHandler;
     _networkSender = networkSender;
     _heartbeatManager = heartbeatManager;
     _queueConfiguration = queueConfiguration;
     _networkInputDisruptor = new Disruptor<InboundMessageProcessingEntry>(() => new InboundMessageProcessingEntry(),new MultiThreadedClaimStrategy(_queueConfiguration.InboundQueueSize), new SleepingWaitStrategy(), new RoundRobinThreadAffinedTaskScheduler(3));
     _outputDisruptor = new Disruptor<OutboundDisruptorEntry>(() => new OutboundDisruptorEntry(), new MultiThreadedClaimStrategy(_queueConfiguration.OutboundQueueSize), new SleepingWaitStrategy(), new RoundRobinThreadAffinedTaskScheduler(2));
 }
        public QueueTriggerAttributeBindingProvider(INameResolver nameResolver,
            IStorageAccountProvider accountProvider,
            IQueueConfiguration queueConfiguration,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            IContextSetter<IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
            ISharedContextProvider sharedContextProvider,
            TextWriter log)
        {
            if (accountProvider == null)
            {
                throw new ArgumentNullException("accountProvider");
            }

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

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

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

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

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

            _nameResolver = nameResolver;
            _accountProvider = accountProvider;
            _queueConfiguration = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter;
            _sharedContextProvider = sharedContextProvider;
            _log = log;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MessageWorkerBase"/> class.
        /// </summary>
        /// <param name="processor">The parent processor.</param>
        /// <param name="name">The name of the worker.</param>
        /// <exception cref="ArgumentNullException"><paramref name="processor"/> is <see langword="null" />.</exception>
        protected MessageWorkerBase(IMessageProcessor processor, string name)
        {
            if (processor == null)
                throw new ArgumentNullException("processor");

            if (name == null)
                throw new ArgumentNullException("name");

            _name = name;

            _processor = processor;
            _container = _processor.Container;
            _configuration = _container.Configuration;
            _repository = _container.Repository;

            _random = new Random();
            _pollTimer = new Timer(PollQueue);
        }
        public static async Task<JobHostContext> CreateAndLogHostStartedAsync(
            JobHost host,
            IStorageAccountProvider storageAccountProvider,
            IQueueConfiguration queueConfiguration,
            ITypeLocator typeLocator,
            IJobActivator activator,
            INameResolver nameResolver,
            IConsoleProvider consoleProvider,
            JobHostConfiguration config,
            CancellationToken shutdownToken,
            CancellationToken cancellationToken,
            IHostIdProvider hostIdProvider = null,
            FunctionExecutor functionExecutor = null,
            IFunctionIndexProvider functionIndexProvider = null,
            IBindingProvider bindingProvider = null,
            IHostInstanceLoggerProvider hostInstanceLogerProvider = null,
            IFunctionInstanceLoggerProvider functionInstanceLoggerProvider = null,
            IFunctionOutputLoggerProvider functionOutputLoggerProvider = null,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher = null,
            SingletonManager singletonManager = null)
        {
            if (hostIdProvider == null)
            {
                hostIdProvider = new DynamicHostIdProvider(storageAccountProvider, () => functionIndexProvider);
            }

            IExtensionTypeLocator extensionTypeLocator = new ExtensionTypeLocator(typeLocator);
            if (backgroundExceptionDispatcher == null)
            {
                backgroundExceptionDispatcher = BackgroundExceptionDispatcher.Instance;
            }
            ContextAccessor<IMessageEnqueuedWatcher> messageEnqueuedWatcherAccessor = new ContextAccessor<IMessageEnqueuedWatcher>();
            ContextAccessor<IBlobWrittenWatcher> blobWrittenWatcherAccessor = new ContextAccessor<IBlobWrittenWatcher>();
            ISharedContextProvider sharedContextProvider = new SharedContextProvider();

            // Create a wrapper TraceWriter that delegates to both the user 
            // TraceWriter specified on Config (if present), as well as to Console
            TraceWriter trace = new ConsoleTraceWriter(config.Tracing, consoleProvider.Out);

            // Register system services with the service container
            config.AddService<INameResolver>(nameResolver);

            ExtensionConfigContext context = new ExtensionConfigContext
            {
                Config = config,
                Trace = trace,
                Host = host
            };
            InvokeExtensionConfigProviders(context);

            IExtensionRegistry extensions = config.GetExtensions();
            ITriggerBindingProvider triggerBindingProvider = DefaultTriggerBindingProvider.Create(nameResolver,
                storageAccountProvider, extensionTypeLocator, hostIdProvider, queueConfiguration, backgroundExceptionDispatcher,
                messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, sharedContextProvider, extensions, trace);

            if (bindingProvider == null)
            {
                bindingProvider = DefaultBindingProvider.Create(nameResolver, storageAccountProvider, extensionTypeLocator, messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, extensions);
            }

            DefaultLoggerProvider loggerProvider = new DefaultLoggerProvider(storageAccountProvider, trace);

            if (singletonManager == null)
            {
                singletonManager = new SingletonManager(storageAccountProvider, backgroundExceptionDispatcher, config.Singleton, trace, config.NameResolver);
            }
            
            using (CancellationTokenSource combinedCancellationSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, shutdownToken))
            {
                CancellationToken combinedCancellationToken = combinedCancellationSource.Token;

                await WriteSiteExtensionManifestAsync(combinedCancellationToken);

                IStorageAccount dashboardAccount = await storageAccountProvider.GetDashboardAccountAsync(combinedCancellationToken);

                IHostInstanceLogger hostInstanceLogger = null;
                if (hostInstanceLogerProvider != null)
                {
                    hostInstanceLogger = await hostInstanceLogerProvider.GetAsync(combinedCancellationToken);
                }
                else
                {
                    hostInstanceLogger = await((IHostInstanceLoggerProvider)loggerProvider).GetAsync(combinedCancellationToken);
                }

                IFunctionInstanceLogger functionInstanceLogger = null;
                if (functionInstanceLoggerProvider != null)
                {
                    functionInstanceLogger = await functionInstanceLoggerProvider.GetAsync(combinedCancellationToken);
                }
                else
                {
                    functionInstanceLogger = (IFunctionInstanceLogger)(await((IFunctionInstanceLoggerProvider)loggerProvider).GetAsync(combinedCancellationToken));
                }

                IFunctionOutputLogger functionOutputLogger = null;
                if (functionOutputLoggerProvider != null)
                {
                    functionOutputLogger = await functionOutputLoggerProvider.GetAsync(combinedCancellationToken);
                }
                else
                {
                    functionOutputLogger = (IFunctionOutputLogger)(await((IFunctionOutputLoggerProvider)loggerProvider).GetAsync(combinedCancellationToken));
                }

                if (functionExecutor == null)
                {
                    functionExecutor = new FunctionExecutor(functionInstanceLogger, functionOutputLogger, backgroundExceptionDispatcher, trace);
                }

                if (functionIndexProvider == null)
                {
                    functionIndexProvider = new FunctionIndexProvider(typeLocator, triggerBindingProvider, bindingProvider, activator, functionExecutor, extensions, singletonManager);
                }

                IFunctionIndex functions = await functionIndexProvider.GetAsync(combinedCancellationToken);
                IListenerFactory functionsListenerFactory = new HostListenerFactory(functions.ReadAll(), singletonManager, activator, nameResolver, trace);

                IFunctionExecutor hostCallExecutor;
                IListener listener;
                HostOutputMessage hostOutputMessage;

                if (dashboardAccount != null)
                {
                    string hostId = await hostIdProvider.GetHostIdAsync(cancellationToken);

                    string sharedQueueName = HostQueueNames.GetHostQueueName(hostId);
                    IStorageQueueClient dashboardQueueClient = dashboardAccount.CreateQueueClient();
                    IStorageQueue sharedQueue = dashboardQueueClient.GetQueueReference(sharedQueueName);
                    IListenerFactory sharedQueueListenerFactory = new HostMessageListenerFactory(sharedQueue,
                        queueConfiguration, backgroundExceptionDispatcher, trace, functions,
                        functionInstanceLogger, functionExecutor);

                    Guid hostInstanceId = Guid.NewGuid();
                    string instanceQueueName = HostQueueNames.GetHostQueueName(hostInstanceId.ToString("N"));
                    IStorageQueue instanceQueue = dashboardQueueClient.GetQueueReference(instanceQueueName);
                    IListenerFactory instanceQueueListenerFactory = new HostMessageListenerFactory(instanceQueue,
                        queueConfiguration, backgroundExceptionDispatcher, trace, functions,
                        functionInstanceLogger, functionExecutor);

                    HeartbeatDescriptor heartbeatDescriptor = new HeartbeatDescriptor
                    {
                        SharedContainerName = HostContainerNames.Hosts,
                        SharedDirectoryName = HostDirectoryNames.Heartbeats + "/" + hostId,
                        InstanceBlobName = hostInstanceId.ToString("N"),
                        ExpirationInSeconds = (int)HeartbeatIntervals.ExpirationInterval.TotalSeconds
                    };

                    IStorageBlockBlob blob = dashboardAccount.CreateBlobClient()
                        .GetContainerReference(heartbeatDescriptor.SharedContainerName)
                        .GetBlockBlobReference(heartbeatDescriptor.SharedDirectoryName + "/" + heartbeatDescriptor.InstanceBlobName);
                    IRecurrentCommand heartbeatCommand = new UpdateHostHeartbeatCommand(new HeartbeatCommand(blob));

                    IEnumerable<MethodInfo> indexedMethods = functions.ReadAllMethods();
                    Assembly hostAssembly = GetHostAssembly(indexedMethods);
                    string displayName = hostAssembly != null ? hostAssembly.GetName().Name : "Unknown";

                    hostOutputMessage = new DataOnlyHostOutputMessage
                    {
                        HostInstanceId = hostInstanceId,
                        HostDisplayName = displayName,
                        SharedQueueName = sharedQueueName,
                        InstanceQueueName = instanceQueueName,
                        Heartbeat = heartbeatDescriptor,
                        WebJobRunIdentifier = WebJobRunIdentifier.Current
                    };

                    hostCallExecutor = CreateHostCallExecutor(instanceQueueListenerFactory, heartbeatCommand,
                        backgroundExceptionDispatcher, shutdownToken, functionExecutor);
                    IListenerFactory hostListenerFactory = new CompositeListenerFactory(functionsListenerFactory,
                        sharedQueueListenerFactory, instanceQueueListenerFactory);
                    listener = CreateHostListener(hostListenerFactory, heartbeatCommand, backgroundExceptionDispatcher, shutdownToken);

                    // Publish this to Azure logging account so that a web dashboard can see it. 
                    await LogHostStartedAsync(functions, hostOutputMessage, hostInstanceLogger, combinedCancellationToken);
                }
                else
                {
                    hostCallExecutor = new ShutdownFunctionExecutor(shutdownToken, functionExecutor);

                    IListener factoryListener = new ListenerFactoryListener(functionsListenerFactory);
                    IListener shutdownListener = new ShutdownListener(shutdownToken, factoryListener);
                    listener = shutdownListener;

                    hostOutputMessage = new DataOnlyHostOutputMessage();
                }

                functionExecutor.HostOutputMessage = hostOutputMessage;

                IEnumerable<FunctionDescriptor> descriptors = functions.ReadAllDescriptors();
                int descriptorsCount = descriptors.Count();

                if (descriptorsCount == 0)
                {
                    trace.Warning("No functions found. Try making job classes and methods public.", TraceSource.Indexing);
                }
                else
                {
                    StringBuilder functionsTrace = new StringBuilder();
                    functionsTrace.AppendLine("Found the following functions:");
                    
                    foreach (FunctionDescriptor descriptor in descriptors)
                    {
                        functionsTrace.AppendLine(descriptor.FullName);
                    }

                    trace.Info(functionsTrace.ToString(), TraceSource.Indexing);
                }

                return new JobHostContext(functions, hostCallExecutor, listener, trace);
            }
        }
Example #52
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QueueManager"/> class.
 /// </summary>
 /// <param name="instanceName">Name of the instance.</param>
 /// <param name="operationsFactory">The operations factory.</param>
 /// <param name="counters">The counters.</param>
 /// <param name="config">The configuration.</param>
 /// <param name="dataAccessFactory">The data access factory.</param>
 /// <param name="errorHandler">The error handler.</param>
 /// <param name="eventLog">The event log.</param>
 public QueueManager(string instanceName, IServiceOperationsFactory operationsFactory, IQueuePerformanceCounters counters, IQueueConfiguration config, IQueueDataAccessFactory dataAccessFactory,
     ErrorHandler errorHandler, IMyEventLog eventLog)
 {
     _handler = null;
     _timers = new TimerBasedExecutionEngine[0];
     _specialTransitionsLock = new object();
     _specialTransitions = new Dictionary<Guid, AsyncHandlerEarlyExitRequest>();
     InstanceName = DecorateInstanceName(instanceName);
     Counters = counters;
     Configuration = config;
     ShuttingDown = false;
     _shutdownEvent = null;
     _disposed = false;
     _dataAccessFactory = dataAccessFactory;
     _errorHandler = errorHandler;
     EventLog = eventLog;
     OperationsFactory = operationsFactory;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="QueueConfigurationBuilder"/> class.
 /// </summary>
 /// <param name="configuration">The queue configuration.</param>
 public QueueConfigurationBuilder(IQueueConfiguration configuration)
     : base(configuration)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="QueueConfigurationBase"/> class.
 /// </summary>
 /// <param name="configuration">The queue configuration.</param>
 public QueueConfigurationBase(IQueueConfiguration configuration)
 {
     _configuration = configuration;
 }
        /// <summary>
        /// Registers a queue with the specified configuration.
        /// </summary>
        /// <param name="queueConfiguration">The queue configuration to register.</param>
        /// <returns>
        /// An instance of <see cref="IQueueContainer" /> that was registered.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">queueConfiguration</exception>
        public IQueueContainer Register(IQueueConfiguration queueConfiguration)
        {
            if (queueConfiguration == null)
                throw new ArgumentNullException(nameof(queueConfiguration));


            var queue = Load(queueConfiguration.Name);

            // update config
            var config = queue.Configuration;

            // copy values
            config.Description = queueConfiguration.Description;
            config.PollTime = queueConfiguration.PollTime;
            config.Priority = queueConfiguration.Priority;
            config.ProcessTimeout = queueConfiguration.ProcessTimeout;
            config.ResponseQueue = queueConfiguration.ResponseQueue;
            config.RetryCount = queueConfiguration.RetryCount;
            config.SubscriberFactory = queueConfiguration.SubscriberFactory;
            config.TimeoutPolicy = queueConfiguration.TimeoutPolicy;
            config.WorkerCount = queueConfiguration.WorkerCount;

            return queue;
        }
        /// <summary>
        /// Adds a queue to the hierarchy.
        /// </summary>
        /// <param name="value">The queue to add.</param>
        /// <returns>The new <see cref="TreeNode"/> for the queue.</returns>
        private TreeNode AddQueue(IQueueConfiguration value)
        {
            this.hierarchy.BeginUpdate();
            try
            {
                // Check if the node already exists or not
                TreeNode queueNode;
                if (this.queues.ContainsKey(value.Name))
                {
                    queueNode = this.queues[value.Name];
                }
                else
                {
                    // Add the new node and store it
                    queueNode = this.AddNode(this.hierarchy.Nodes[0], value.Name, "queue", value);
                    this.queues.Add(value.Name, queueNode);
                }

                // If the node already exists, then the project will use it so this will be a safe call
                // The only time this method can be called twice if the actual queue configuration is set
                queueNode.Tag = value;
                return queueNode;
            }
            finally
            {
                this.hierarchy.EndUpdate();
            }
        }
        private IQueueContainer CreateContainer(IQueueConfiguration configuration)
        {
            var collection = GetCollection(configuration.Name);
            var repository = new QueueRepository(collection);

            var queue = new QueueContainer(configuration, repository);

            return queue;
        }
        public BlobTriggerBinding(ParameterInfo parameter,
            IArgumentBinding<IStorageBlob> argumentBinding,
            IStorageAccount hostAccount,
            IStorageAccount dataAccount,
            IBlobPathSource path,
            IHostIdProvider hostIdProvider,
            IQueueConfiguration queueConfiguration,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            IContextSetter<IBlobWrittenWatcher> blobWrittenWatcherSetter,
            IContextSetter<IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
            ISharedContextProvider sharedContextProvider,
            TraceWriter trace)
        {
            if (parameter == null)
            {
                throw new ArgumentNullException("parameter");
            }

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

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

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

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

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

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

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

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

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

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

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

            _parameter = parameter;
            _argumentBinding = argumentBinding;
            _hostAccount = hostAccount;
            _dataAccount = dataAccount;
            StorageClientFactoryContext context = new StorageClientFactoryContext
            {
                Parameter = parameter
            };
            _blobClient = dataAccount.CreateBlobClient(context);
            _accountName = BlobClient.GetAccountName(_blobClient);
            _path = path;
            _hostIdProvider = hostIdProvider;
            _queueConfiguration = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _blobWrittenWatcherSetter = blobWrittenWatcherSetter;
            _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter;
            _sharedContextProvider = sharedContextProvider;
            _trace = trace;
            _converter = CreateConverter(_blobClient);
            _bindingDataContract = CreateBindingDataContract(path);
        }
        public BlobListenerFactory(IHostIdProvider hostIdProvider,
            IQueueConfiguration queueConfiguration,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            IContextSetter<IBlobWrittenWatcher> blobWrittenWatcherSetter,
            IContextSetter<IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
            ISharedContextProvider sharedContextProvider,
            TextWriter log,
            string functionId,
            IStorageAccount account,
            IStorageBlobContainer container,
            IBlobPathSource input,
            ITriggeredFunctionExecutor<IStorageBlob> executor)
        {
            if (hostIdProvider == null)
            {
                throw new ArgumentNullException("hostIdProvider");
            }

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

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

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

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

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

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

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

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

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

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

            _hostIdProvider = hostIdProvider;
            _queueConfiguration = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _blobWrittenWatcherSetter = blobWrittenWatcherSetter;
            _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter;
            _sharedContextProvider = sharedContextProvider;
            _log = log;
            _functionId = functionId;
            _account = account;
            _container = container;
            _input = input;
            _executor = executor;
        }
        public BlobTriggerBinding(string parameterName,
            IArgumentBinding<IStorageBlob> argumentBinding,
            IStorageAccount account,
            IBlobPathSource path,
            IHostIdProvider hostIdProvider,
            IQueueConfiguration queueConfiguration,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            IContextSetter<IBlobWrittenWatcher> blobWrittenWatcherSetter,
            IContextSetter<IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
            ISharedContextProvider sharedContextProvider,
            TextWriter log)
        {
            if (argumentBinding == null)
            {
                throw new ArgumentNullException("argumentBinding");
            }

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

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

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

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

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

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

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

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

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

            _parameterName = parameterName;
            _argumentBinding = argumentBinding;
            _account = account;
            _client = account.CreateBlobClient();
            _accountName = BlobClient.GetAccountName(_client);
            _path = path;
            _hostIdProvider = hostIdProvider;
            _queueConfiguration = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _blobWrittenWatcherSetter = blobWrittenWatcherSetter;
            _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter;
            _sharedContextProvider = sharedContextProvider;
            _log = log;
            _converter = CreateConverter(_client);
            _bindingDataContract = CreateBindingDataContract(path);
        }