public ServiceBusListener(
            string functionId,
            ServiceBusEntityType entityType,
            string entityPath,
            bool isSessionsEnabled,
            bool autoCompleteMessagesOptionEvaluatedValue,
            ITriggeredFunctionExecutor triggerExecutor,
            ServiceBusOptions options,
            string connection,
            MessagingProvider messagingProvider,
            ILoggerFactory loggerFactory,
            bool singleDispatch,
            ServiceBusClientFactory clientFactory)
        {
            _functionId        = functionId;
            _entityType        = entityType;
            _entityPath        = entityPath;
            _isSessionsEnabled = isSessionsEnabled;
            _autoCompleteMessagesOptionEvaluatedValue = autoCompleteMessagesOptionEvaluatedValue;
            _triggerExecutor         = triggerExecutor;
            _cancellationTokenSource = new CancellationTokenSource();
            _messagingProvider       = messagingProvider;
            _loggerFactory           = loggerFactory;
            _logger = loggerFactory.CreateLogger <ServiceBusListener>();

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

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

            _messageProcessor = new Lazy <MessageProcessor>(
                () => _messagingProvider.CreateMessageProcessor(
                    _client.Value,
                    _entityPath,
                    options.ToProcessorOptions(_autoCompleteMessagesOptionEvaluatedValue)));

            _sessionMessageProcessor = new Lazy <SessionMessageProcessor>(
                () => _messagingProvider.CreateSessionMessageProcessor(
                    _client.Value,
                    _entityPath,
                    options.ToSessionProcessorOptions(_autoCompleteMessagesOptionEvaluatedValue)));

            _scaleMonitor = new Lazy <ServiceBusScaleMonitor>(
                () => new ServiceBusScaleMonitor(
                    _functionId,
                    _entityType,
                    _entityPath,
                    connection,
                    _batchReceiver,
                    _loggerFactory,
                    clientFactory));

            _singleDispatch    = singleDispatch;
            _serviceBusOptions = options;
        }
Пример #2
0
        public void ToProcessorOptions_DynamicConcurrencyEnabled_ReturnsExpectedValue()
        {
            ServiceBusOptions sbOptions = new ServiceBusOptions
            {
                AutoCompleteMessages       = false,
                PrefetchCount              = 123,
                MaxAutoLockRenewalDuration = TimeSpan.FromSeconds(123),
                MaxConcurrentCalls         = 123
            };

            ServiceBusProcessorOptions processorOptions = sbOptions.ToProcessorOptions(true, true);

            Assert.AreEqual(true, processorOptions.AutoCompleteMessages);
            Assert.AreEqual(sbOptions.PrefetchCount, processorOptions.PrefetchCount);
            Assert.AreEqual(sbOptions.MaxAutoLockRenewalDuration, processorOptions.MaxAutoLockRenewalDuration);
            Assert.AreEqual(1, processorOptions.MaxConcurrentCalls);
        }
Пример #3
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}'");
        }