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); }
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)); }
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); } }
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(); }
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(); }
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(); }
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(); }
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); }