Beispiel #1
0
        public Task <IListener> CreateAsync(CancellationToken cancellationToken)
        {
            var triggerExecutor = new ServiceBusTriggerExecutor(_executor);
            var listener        = new ServiceBusListener(_queueName, triggerExecutor, _config, _account);

            return(Task.FromResult <IListener>(listener));
        }
Beispiel #2
0
        public Task <IListener> CreateAsync(CancellationToken cancellationToken)
        {
            var triggerExecutor = new ServiceBusTriggerExecutor(_executor);
            var listener        = new ServiceBusListener(_entityPath, _isSessionsEnabled, triggerExecutor, _options, _account, _messagingProvider);

            return(Task.FromResult <IListener>(listener));
        }
Beispiel #3
0
        public ServiceBusListener(string functionId, EntityType entityType, string entityPath, bool isSessionsEnabled, ServiceBusTriggerExecutor triggerExecutor,
                                  ServiceBusOptions config, ServiceBusAccount serviceBusAccount, MessagingProvider messagingProvider, ILoggerFactory loggerFactory)
        {
            _functionId              = functionId;
            _entityType              = entityType;
            _entityPath              = entityPath;
            _isSessionsEnabled       = isSessionsEnabled;
            _triggerExecutor         = triggerExecutor;
            _cancellationTokenSource = new CancellationTokenSource();
            _messagingProvider       = messagingProvider;
            _serviceBusAccount       = serviceBusAccount;
            _loggerFactory           = loggerFactory;
            _receiver     = CreateMessageReceiver();
            _scaleMonitor = new Lazy <ServiceBusScaleMonitor>(() => new ServiceBusScaleMonitor(_functionId, _entityType, _entityPath, _serviceBusAccount.ConnectionString, _receiver, _loggerFactory));

            if (_isSessionsEnabled)
            {
                _sessionMessageProcessor = _messagingProvider.CreateSessionMessageProcessor(_entityPath, _serviceBusAccount.ConnectionString);
            }
            else
            {
                _messageProcessor = _messagingProvider.CreateMessageProcessor(entityPath, _serviceBusAccount.ConnectionString);
            }
            _serviceBusOptions = config;
        }
 public ServiceBusListener(MessagingFactory messagingFactory, string entityPath, ServiceBusTriggerExecutor triggerExecutor)
 {
     _messagingFactory = messagingFactory;
     _entityPath = entityPath;
     _triggerExecutor = triggerExecutor;
     _cancellationTokenSource = new CancellationTokenSource();
 }
 public ServiceBusListener(MessagingFactory messagingFactory, string entityPath, ServiceBusTriggerExecutor triggerExecutor)
 {
     _messagingFactory        = messagingFactory;
     _entityPath              = entityPath;
     _triggerExecutor         = triggerExecutor;
     _cancellationTokenSource = new CancellationTokenSource();
 }
Beispiel #6
0
 public ServiceBusListener(MessagingFactory messagingFactory, string entityPath, ServiceBusTriggerExecutor triggerExecutor, ServiceBusConfiguration config)
 {
     _messagingFactory        = messagingFactory;
     _entityPath              = entityPath;
     _triggerExecutor         = triggerExecutor;
     _cancellationTokenSource = new CancellationTokenSource();
     _messageProcessor        = config.MessagingProvider.CreateMessageProcessor(entityPath);
 }
 public ServiceBusListener(MessagingFactory messagingFactory, string entityPath, ServiceBusTriggerExecutor triggerExecutor, ServiceBusConfiguration config)
 {
     _messagingFactory = messagingFactory;
     _entityPath = entityPath;
     _triggerExecutor = triggerExecutor;
     _cancellationTokenSource = new CancellationTokenSource();
     _messageProcessor = config.MessagingProvider.CreateMessageProcessor(entityPath);
 }
 public ServiceBusListener(string entityPath, ServiceBusTriggerExecutor triggerExecutor, ServiceBusConfiguration config, ServiceBusAccount serviceBusAccount)
 {
     _entityPath              = entityPath;
     _triggerExecutor         = triggerExecutor;
     _cancellationTokenSource = new CancellationTokenSource();
     _messagingProvider       = config.MessagingProvider;
     _serviceBusAccount       = serviceBusAccount;
     _messageProcessor        = config.MessagingProvider.CreateMessageProcessor(entityPath, _serviceBusAccount.ConnectionString);
 }
Beispiel #9
0
        public Task <IListener> CreateAsync(CancellationToken cancellationToken)
        {
            string entityPath = EntityNameHelper.FormatSubscriptionPath(_topicName, _subscriptionName);

            ServiceBusTriggerExecutor triggerExecutor = new ServiceBusTriggerExecutor(_executor);
            var listener = new ServiceBusListener(entityPath, triggerExecutor, _config, _account);

            return(Task.FromResult <IListener>(listener));
        }
        public async Task <IListener> CreateAsync(IFunctionExecutor executor, CancellationToken cancellationToken)
        {
            // Must create all messaging entities before creating message receivers and calling OnMessage.
            // Otherwise, some function could start to execute and try to output messages to entities that don't yet
            // exist.
            await _namespaceManager.CreateQueueIfNotExistsAsync(_queueName, cancellationToken);

            ITriggerExecutor <BrokeredMessage> triggerExecutor = new ServiceBusTriggerExecutor(_instanceFactory,
                                                                                               executor);

            return(new ServiceBusListener(_messagingFactory, _queueName, triggerExecutor));
        }
        public async Task<IListener> CreateAsync(ListenerFactoryContext context)
        {
            if (_accessRights == AccessRights.Manage)
            {
                // Must create all messaging entities before creating message receivers and calling OnMessage.
                // Otherwise, some function could start to execute and try to output messages to entities that don't yet
                // exist.
                await _namespaceManager.CreateQueueIfNotExistsAsync(_queueName, context.CancellationToken);
            }

            ServiceBusTriggerExecutor triggerExecutor = new ServiceBusTriggerExecutor(_executor);
            return new ServiceBusListener(_messagingFactory, _queueName, triggerExecutor);
        }
        public async Task <IListener> CreateAsync(CancellationToken cancellationToken)
        {
            if (_accessRights == AccessRights.Manage)
            {
                // Must create all messaging entities before creating message receivers and calling OnMessage.
                // Otherwise, some function could start to execute and try to output messages to entities that don't yet
                // exist.
                await _namespaceManager.CreateQueueIfNotExistsAsync(_queueName, cancellationToken);
            }

            ServiceBusTriggerExecutor triggerExecutor = new ServiceBusTriggerExecutor(_executor);

            return(new ServiceBusListener(_messagingFactory, _queueName, triggerExecutor, _config));
        }
        public async Task<IListener> CreateAsync(CancellationToken cancellationToken)
        {
            if (_accessRights == AccessRights.Manage)
            {
                // Must create all messaging entities before creating message receivers and calling OnMessage.
                // Otherwise, some function could start to execute and try to output messages to entities that don't yet
                // exist.
                await _namespaceManager.CreateTopicIfNotExistsAsync(_topicName, cancellationToken);
                await _namespaceManager.CreateSubscriptionIfNotExistsAsync(_topicName, _subscriptionName, cancellationToken);
            }

            string entityPath = SubscriptionClient.FormatSubscriptionPath(_topicName, _subscriptionName);

            ServiceBusTriggerExecutor triggerExecutor = new ServiceBusTriggerExecutor(_executor);
            return new ServiceBusListener(_messagingFactory, entityPath, triggerExecutor, _config);
        }
Beispiel #14
0
        public async Task <IListener> CreateAsync(IFunctionExecutor executor, CancellationToken cancellationToken)
        {
            // Must create all messaging entities before creating message receivers and calling OnMessage.
            // Otherwise, some function could start to execute and try to output messages to entities that don't yet
            // exist.
            await _namespaceManager.CreateTopicIfNotExistsAsync(_topicName, cancellationToken);

            await _namespaceManager.CreateSubscriptionIfNotExistsAsync(_topicName, _subscriptionName,
                                                                       cancellationToken);

            string entityPath = SubscriptionClient.FormatSubscriptionPath(_topicName, _subscriptionName);

            ITriggerExecutor <BrokeredMessage> triggerExecutor = new ServiceBusTriggerExecutor(_instanceFactory,
                                                                                               executor);

            return(new ServiceBusListener(_messagingFactory, entityPath, triggerExecutor));
        }
        public ServiceBusListener(string entityPath, bool isSessionsEnabled, ServiceBusTriggerExecutor triggerExecutor, ServiceBusOptions config, ServiceBusAccount serviceBusAccount, MessagingProvider messagingProvider)
        {
            _entityPath              = entityPath;
            _isSessionsEnabled       = isSessionsEnabled;
            _triggerExecutor         = triggerExecutor;
            _cancellationTokenSource = new CancellationTokenSource();
            _messagingProvider       = messagingProvider;
            _serviceBusAccount       = serviceBusAccount;

            if (_isSessionsEnabled)
            {
                _sessionMessageProcessor = _messagingProvider.CreateSessionMessageProcessor(entityPath, _serviceBusAccount.ConnectionString);
            }
            else
            {
                _messageProcessor = _messagingProvider.CreateMessageProcessor(entityPath, _serviceBusAccount.ConnectionString);
            }
            _serviceBusOptions = config;
        }
        public ServiceBusListenerTests()
        {
            _mockExecutor = new Mock<ITriggeredFunctionExecutor>(MockBehavior.Strict);

            string testConnection = "Endpoint=sb://test.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=abc123=";
            MessagingFactory messagingFactory = MessagingFactory.CreateFromConnectionString(testConnection);
            OnMessageOptions messageOptions = new OnMessageOptions();
            _mockMessageProcessor = new Mock<MessageProcessor>(MockBehavior.Strict, messageOptions);
            
            ServiceBusConfiguration config = new ServiceBusConfiguration
            {
                MessageOptions = messageOptions
            };
            Mock<MessagingProvider> mockMessagingProvider = new Mock<MessagingProvider>(MockBehavior.Strict, config);
            config.MessagingProvider = mockMessagingProvider.Object;

            mockMessagingProvider.Setup(p => p.CreateMessageProcessor(_entityPath))
                .Returns(_mockMessageProcessor.Object);

            ServiceBusTriggerExecutor triggerExecutor = new ServiceBusTriggerExecutor(_mockExecutor.Object);
            _listener = new ServiceBusListener(messagingFactory, _entityPath, triggerExecutor, config);
        }