public ServiceBusListener(
            string functionId,
            EntityType entityType,
            string entityPath,
            bool isSessionsEnabled,
            ITriggeredFunctionExecutor triggerExecutor,
            ServiceBusOptions options,
            string connection,
            MessagingProvider messagingProvider,
            ILoggerFactory loggerFactory,
            bool singleDispatch,
            ServiceBusClientFactory clientFactory)
        {
            _functionId              = functionId;
            _entityType              = entityType;
            _entityPath              = entityPath;
            _isSessionsEnabled       = isSessionsEnabled;
            _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));
            _messageProcessor        = new Lazy <MessageProcessor>(() => _messagingProvider.CreateMessageProcessor(_client.Value, _entityPath));
            _sessionMessageProcessor = new Lazy <SessionMessageProcessor>(() => _messagingProvider.CreateSessionMessageProcessor(_client.Value, _entityPath));

            _scaleMonitor      = new Lazy <ServiceBusScaleMonitor>(() => new ServiceBusScaleMonitor(_functionId, _entityType, _entityPath, connection, _batchReceiver, _loggerFactory, clientFactory));
            _singleDispatch    = singleDispatch;
            _serviceBusOptions = options;
        }
        public void CreateMessageReceiver_ReturnsExpectedReceiver()
        {
            string defaultConnection = "Endpoint=sb://default.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=abc123=";
            var    config            = new ServiceBusOptions
            {
                ConnectionString = defaultConnection
            };
            var provider = new MessagingProvider(new OptionsWrapper <ServiceBusOptions>(config));
            var receiver = provider.CreateBatchMessageReceiver("entityPath", defaultConnection);

            Assert.AreEqual("entityPath", receiver.EntityPath);

            var receiver2 = provider.CreateBatchMessageReceiver("entityPath", defaultConnection);

            Assert.AreSame(receiver, receiver2);

            config.PrefetchCount = 100;
            receiver             = provider.CreateBatchMessageReceiver("entityPath1", defaultConnection);
            Assert.AreEqual(100, receiver.PrefetchCount);
        }
예제 #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}'");
        }
예제 #4
0
 private Lazy <ServiceBusReceiver> CreateMessageReceiver()
 {
     return(new Lazy <ServiceBusReceiver>(() => _messagingProvider.CreateBatchMessageReceiver(_entityPath, _serviceBusAccount.ConnectionString)));
 }