Example #1
0
        // initialize following fields async
        // _triggerExecutor --> register messageHandler
        // _sharedQueuelistener --> dequeue messages and call messageHandler
        // _sharedQueueWriter --> enqueue messages
        internal async Task InitializeAsync(CancellationToken cancellationToken)
        {
            if (_state != State.Created)
            {
                // only initialized once, since _state is incremental
                throw new InvalidOperationException(ErrorMessage(State.Created, _state));
            }

            // concurrent dictionary that we can register messageHandler
            _triggerExecutor = new SharedQueueExecutor();

            try
            {
                string hostId = await _hostIdProvider.GetHostIdAsync(cancellationToken);

                // one host level shared queue
                // queue is not created here, only after 1st message added
                var sharedQueue = HostQueueNames.GetHostSharedQueueName(hostId);
                // default host level poison queue
                var sharedPoisonQueue = HostQueueNames.GetHostSharedPoisonQueueName(hostId);

                // queueWatcher will update queueListener's polling interval when queueWriter performes an enqueue operation
                _sharedQueueWriter = _queueFactory.GetQueueWriter <QueueMessage>(sharedQueue);

                _sharedQueuelistener = _queueFactory.CreateQueueListenr(sharedQueue, sharedPoisonQueue, _triggerExecutor.ExecuteAsync);
            }
            catch (Exception ex)
            {
                // initialization exception will fail all registrations
                _initializationEx = ex;
            }

            _state = State.Initialized;
        }
Example #2
0
        // initialize following fields async
        // _triggerExecutor --> register messageHandler
        // _sharedQueuelistener --> dequeue messages and call messageHandler
        // _sharedQueueWriter --> enqueue messages
        internal async Task InitializeAsync(CancellationToken cancellationToken)
        {
            if (_state != State.Created)
            {
                // only initialized once, since _state is incremental
                throw new InvalidOperationException(ErrorMessage(State.Created, _state));
            }

            // concurrent dictionary that we can register messageHandler
            _triggerExecutor = new SharedQueueExecutor();

            try
            {
                IStorageQueueClient primaryQueueClient = (await _accountProvider.GetStorageAccountAsync(cancellationToken)).CreateQueueClient();
                string hostId = await _hostIdProvider.GetHostIdAsync(cancellationToken);

                // one host level shared queue
                // queue is not created here, only after 1st message added
                IStorageQueue sharedQueue = primaryQueueClient.GetQueueReference(HostQueueNames.GetHostSharedQueueName(hostId));
                // default host level poison queue
                IStorageQueue sharedPoisonQueue = primaryQueueClient.GetQueueReference(HostQueueNames.GetHostSharedPoisonQueueName(hostId));

                // queueWatcher will update queueListener's polling interval when queueWriter performes an enqueue operation
                SharedQueueWatcher sharedQueueWatcher = _sharedContextProvider.GetOrCreateInstance <SharedQueueWatcher>(
                    new SharedQueueWatcherFactory(_messageEnqueuedWatcherSetter));
                _sharedQueueWriter = new SharedQueueWriter(sharedQueue, sharedQueueWatcher);

                // use default poisonQueue setup
                _sharedQueuelistener = new QueueListener(sharedQueue, sharedPoisonQueue, _triggerExecutor,
                                                         _exceptionHandler, _loggerFactory, sharedQueueWatcher, _queueConfiguration);
            }
            catch (Exception ex)
            {
                // initialization exception will fail all registrations
                _initializationEx = ex;
            }

            _state = State.Initialized;
        }