Beispiel #1
0
        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();
        }
Beispiel #2
0
        private static IConnection OpenNewConnection(HostConfiguration hostConfig)
        {
            if (hostConfig == null)
            {
                throw new ArgumentNullException("hostConfig");
            }

            var factory = new ConnectionFactory
            {
                HostName    = hostConfig.HostName,
                VirtualHost = hostConfig.VirtualHost,
                Port        = hostConfig.Port,
                UserName    = hostConfig.Username,
                Password    = hostConfig.Password
            };

            return(factory.CreateConnection());
        }
Beispiel #3
0
        public static IModel OpenChannelToHost(HostConfiguration hostConfig)
        {
            if (hostConfig == null)
            {
                throw new ArgumentNullException("hostConfig");
            }

            if (ConnectionPool.ContainsKey(hostConfig) && ConnectionPool[hostConfig].IsOpen)
            {
                return(ConnectionPool[hostConfig].CreateModel());
            }

            var newConnection = OpenNewConnection(hostConfig);

            ConnectionPool.AddOrUpdate(hostConfig, newConnection, (config, oldValue) => newConnection);
            var channel = newConnection.CreateModel();

            newConnection.AutoClose = true; // Set the connection to auto close after opening first channel
            return(channel);
        }
Beispiel #4
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();
        }