コード例 #1
0
        protected void CreateQueue(QueueConfiguration queueConfig)
        {
            if (queueConfig == null)
            {
                throw new ArgumentNullException("queueConfig");
            }
            if (Channel == null || Channel.IsClosed)
            {
                throw new InvalidOperationException("Cannot create queue - channel is closed or null.");
            }
            if (queueConfig.Exchange == null)
            {
                throw new InvalidOperationException("Unable to create queue - queue configuration specifies null exchange configuration.");
            }

            Log.DebugFormat(CultureInfo.InvariantCulture, "Creating exchange {0}.", queueConfig.Exchange.Name);
            CreateExchange(queueConfig.Exchange);

            Log.DebugFormat(CultureInfo.InvariantCulture, "Creating queue {0}.", queueConfig.Name);
            Channel.QueueDeclare(
                queueConfig.Name,
                queueConfig.IsDurable,
                queueConfig.IsExclusive,
                queueConfig.AutoDelete,
                null
                );

            BindQueueToExchange(queueConfig);
        }
コード例 #2
0
        public static IMessagePublisher GetPublisher(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (!Publishers.ContainsKey(name))
            {
                throw new RabbitConfigurationException(String.Format(CultureInfo.InvariantCulture,
                                                                     "A publisher with name \"{0}\" could not be found in the configuration file.", name));
            }

            var publisherConfig = Publishers[name];
            var hostConfig      = GetHostConfiguration(publisherConfig.HostName);
            var exchangeConfig  = GetExchangeConfiguration(publisherConfig.ExchangeName);
            QueueConfiguration deadLetterQueueConfig = null;

            if (publisherConfig.MessagesMustBeRouted)
            {
                if (String.IsNullOrWhiteSpace(publisherConfig.DeadLetterQueueName))
                {
                    throw new RabbitConfigurationException(String.Format(CultureInfo.InvariantCulture,
                                                                         "Publisher \"{0}\" has \"MessagesMustBeRouted\" flag set to true but does not specify a dead letter queue.", name));
                }
                deadLetterQueueConfig = GetQueueConfiguration(publisherConfig.DeadLetterQueueName);
            }
            return(new RabbitPublisher(hostConfig, exchangeConfig, publisherConfig.MessagesMustBeRouted, deadLetterQueueConfig));
        }
コード例 #3
0
ファイル: RabbitMessenger.cs プロジェクト: sjlbos/SENG462_DTS
 private void BindQueueToExchange(QueueConfiguration queueConfig)
 {
     foreach (var bindingKey in queueConfig.BindingKeys)
     {
         Log.DebugFormat(CultureInfo.InvariantCulture, "Binding queue {0} to exchange {1} with binding key {2}.", 
             queueConfig.Name, 
             queueConfig.Exchange.Name, 
             bindingKey);
         Channel.QueueBind(queueConfig.Name, queueConfig.Exchange.Name, bindingKey);
     }
 }
コード例 #4
0
 private void BindQueueToExchange(QueueConfiguration queueConfig)
 {
     foreach (var bindingKey in queueConfig.BindingKeys)
     {
         Log.DebugFormat(CultureInfo.InvariantCulture, "Binding queue {0} to exchange {1} with binding key {2}.",
                         queueConfig.Name,
                         queueConfig.Exchange.Name,
                         bindingKey);
         Channel.QueueBind(queueConfig.Name, queueConfig.Exchange.Name, bindingKey);
     }
 }
コード例 #5
0
ファイル: RabbitReceiver.cs プロジェクト: sjlbos/SENG462_DTS
        public RabbitReceiver(  HostConfiguration hostConfig, 
                                QueueConfiguration queueConfig, 
                                bool autoAckMessages = true , 
                                bool requeueRejectedMessages = true)
            :base(hostConfig)
        {
            if (queueConfig == null)
                throw new ArgumentNullException("queueConfig");

            _queueConfig = queueConfig;
            _autoAckMessages = autoAckMessages;
            _requeueRejectedMessages = requeueRejectedMessages;
            
            InitializeConnection();
        }
コード例 #6
0
ファイル: RabbitReceiver.cs プロジェクト: sjlbos/SENG462_DTS
        public RabbitReceiver(HostConfiguration hostConfig,
                              QueueConfiguration queueConfig,
                              bool autoAckMessages         = true,
                              bool requeueRejectedMessages = true)
            : base(hostConfig)
        {
            if (queueConfig == null)
            {
                throw new ArgumentNullException("queueConfig");
            }

            _queueConfig             = queueConfig;
            _autoAckMessages         = autoAckMessages;
            _requeueRejectedMessages = requeueRejectedMessages;

            InitializeConnection();
        }
コード例 #7
0
ファイル: RabbitPublisher.cs プロジェクト: sjlbos/SENG462_DTS
        public RabbitPublisher(
            HostConfiguration hostConfig, 
            ExchangeConfiguration exchangeConfig, 
            bool messagesMustBeRouted,
            QueueConfiguration deadLetterQueueConfig
            ) 
        : base(hostConfig)
        {
            if (exchangeConfig == null)
                throw new ArgumentNullException("exchangeConfig");
            if (messagesMustBeRouted && deadLetterQueueConfig == null)
                throw new ArgumentNullException("deadLetterQueueConfig");

            _exchangeConfig = exchangeConfig;
            _messagesMustBeRouted = messagesMustBeRouted;
            _deadLetterQueueConfig = deadLetterQueueConfig;

            InitializeConnection();
        }
コード例 #8
0
        public RabbitPublisher(
            HostConfiguration hostConfig,
            ExchangeConfiguration exchangeConfig,
            bool messagesMustBeRouted,
            QueueConfiguration deadLetterQueueConfig
            )
            : base(hostConfig)
        {
            if (exchangeConfig == null)
            {
                throw new ArgumentNullException("exchangeConfig");
            }
            if (messagesMustBeRouted && deadLetterQueueConfig == null)
            {
                throw new ArgumentNullException("deadLetterQueueConfig");
            }

            _exchangeConfig        = exchangeConfig;
            _messagesMustBeRouted  = messagesMustBeRouted;
            _deadLetterQueueConfig = deadLetterQueueConfig;

            InitializeConnection();
        }
コード例 #9
0
ファイル: RabbitMessenger.cs プロジェクト: sjlbos/SENG462_DTS
        protected void CreateQueue(QueueConfiguration queueConfig)
        {
            if (queueConfig == null)
                throw new ArgumentNullException("queueConfig");
            if (Channel == null || Channel.IsClosed)
                throw new InvalidOperationException("Cannot create queue - channel is closed or null.");
            if (queueConfig.Exchange == null)
                throw new InvalidOperationException("Unable to create queue - queue configuration specifies null exchange configuration.");

            Log.DebugFormat(CultureInfo.InvariantCulture, "Creating exchange {0}.", queueConfig.Exchange.Name);
            CreateExchange(queueConfig.Exchange);

            Log.DebugFormat(CultureInfo.InvariantCulture, "Creating queue {0}.", queueConfig.Name);
            Channel.QueueDeclare(
                queueConfig.Name,
                queueConfig.IsDurable,
                queueConfig.IsExclusive,
                queueConfig.AutoDelete,
                null
                );

            BindQueueToExchange(queueConfig);
        }