예제 #1
0
        public MessageQueueWorker(QueueConfig queueConfig, Func <IQueueConsumer> consumerFactory, IMessageQueueCommandExecutor commandExecutor, Func <IMessageQueueSession, IMessageQueue> messageQueueFactory)
        {
            if (queueConfig == null)
            {
                throw new ArgumentNullException("queueConfig");
            }

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

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

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

            _queueConfig         = queueConfig;
            _consumerFactory     = consumerFactory;
            _commandExecutor     = commandExecutor;
            _messageQueueFactory = messageQueueFactory;

            _startedEvent = new CountdownEvent(queueConfig.QueueWorkerThreadCount);
            _stoppedEvent = new CountdownEvent(queueConfig.QueueWorkerThreadCount);
        }
예제 #2
0
        private void CreateQueue(QueueConfig queueConfig, Func <IQueueConsumer> consumer, Func <IMessageQueueSession, IMessageQueue> queueFactory)
        {
            if (consumer == null)
            {
                throw new ArgumentNullException("consumer");
            }

            // Очередь должна быть создана вне зависимости от того, когда начнется ее прослушивание
            _queueCommandExecutor.Execute(session => queueFactory(session));


            // Создание менеджера для управления рабочим потоком очереди сообщений

            var queueWorker = new MessageQueueWorker(queueConfig, consumer, _queueCommandExecutor, queueFactory);

            _queueWorkerContainer.RegisterWorker(queueConfig.QueueName, queueWorker);
        }
예제 #3
0
        private QueueConfig CreateQueueConfig(string queue, Action <IQueueConfig> queueConfig)
        {
            if (string.IsNullOrWhiteSpace(queue))
            {
                throw new ArgumentNullException("queue");
            }

            var config = new QueueConfig(_exchangeName, queue);

            if (_defaultQueueConfig != null)
            {
                _defaultQueueConfig(config);
            }

            if (queueConfig != null)
            {
                queueConfig(config);
            }

            return(config);
        }