Esempio n. 1
0
        public void Subscribe(QueuesConfiguration queuesConfiguration)
        {
            if (Log.IsInfoEnabled)
                Log.Info("Starting subscribing to queues");

            foreach (var queue in queuesConfiguration.Queues)
            {
                if(ShouldStartListener(queue))
                {
                    if (Log.IsInfoEnabled)
                        Log.Info("Subscribing to: {0}", queue.Name);

                    var queueThread = new Thread(StartQueue);
                    queueThread.Start(queue);

                    _queueThreads.Add(queueThread);
                }

                if (ShouldStartDispatcher(queue))
                {
                    if (Log.IsInfoEnabled)
                        Log.Info("Starting dispatcher for: {0}", queue.Name);

                    var dispatcherThread = new Thread(StartDispatcher);
                    dispatcherThread.Start(queue);

                    _dispatcherThread.Add(dispatcherThread);
                }
            }

            _isFirstTime = false;
            _queuesConfiguration = queuesConfiguration;
        }
        public static QueuesConfiguration FromCode(params Queue[] queues)
        {
            var conf = new QueuesConfiguration();
            if (queues != null && queues.Length > 0)
                conf._queues.AddRange(queues);

            return conf;
        }
        public static QueuesConfiguration FromConfiguration()
        {
            var queuesConfigurations = new QueuesConfiguration();

            var queueConfigurationSection = ConfigurationManager.GetSection("QueueConfigurationSection") as QueueConfigurationSection;
            if(queueConfigurationSection != null)
            {
                queuesConfigurations._queues.AddRange(from QueueElement queue in queueConfigurationSection.Queues
                                select new Queue
                                           {
                                               Name = queue.Name,
                                               RequiresAck = queue.AckRequired,
                                               Durable = queue.Durable,
                                               MaxThreads = queue.MaxThreads
                                           });
            }

            return queuesConfigurations;
        }
Esempio n. 4
0
        public Rabbit DeclareQueues(QueuesConfiguration queuesConfiguration)
        {
            if (Log.IsInfoEnabled)
                Log.Info("Declaring Queues...");

            var channel = ComponentLocator.Current.Get<IModel>();

            foreach (var queue in queuesConfiguration.Queues)
            {
                if (Log.IsDebugEnabled)
                    Log.Debug("Declaring Queue: {0}, durable: {1}, exclusive: {2}, autodelete: {3}", queue.Name, queue.Durable, false, false, null);

                channel.QueueDeclare(queue.Name, queue.Durable, false, false, null);
            }

            _queuesConfiguration = queuesConfiguration;

            if (Log.IsInfoEnabled)
                Log.Info("Queues declared.");
            return this;
        }